-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathpkcs11sign.cpp
40 lines (35 loc) · 940 Bytes
/
pkcs11sign.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <Container.h>
#include <crypto/PKCS11Signer.h>
#include <iostream>
#include <memory>
#include <sstream>
using namespace digidoc;
static std::ostream &operator<<(std::ostream &s, const Exception &e)
{
s << e.file() << ":" << e.line() << " code(" << e.code() << ") " << e.msg() << std::endl;
for(const Exception &ex: e.causes())
s << ex;
return s;
}
int main()
{
try
{
digidoc::initialize();
std::unique_ptr<Container> doc(Container::createPtr("/tmp/test.asice"));
std::unique_ptr<std::stringstream> s(new std::stringstream);
*s << "test";
doc->addDataFile(std::move(s), "test.txt", "text/plain");
PKCS11Signer signer;
signer.setPin("00000");
signer.setProfile("BES");
doc->sign(&signer);
doc->save();
digidoc::terminate();
}
catch(const Exception &e)
{
std::cout << e;
}
return 0;
}