34 lines
820 B
C++
34 lines
820 B
C++
#include <Void/Security/Authorization.hpp>
|
|
#include <Void/Security/Envelope.hpp>
|
|
#include <Void/Security/SecureBuffer.hpp>
|
|
#include <Void/Security/Security.hpp>
|
|
|
|
#include <vector>
|
|
|
|
int main()
|
|
{
|
|
Void::Security::SecretKeyRing ring;
|
|
if (!ring.generate_and_add_key("v1", true).has_value()) {
|
|
return 1;
|
|
}
|
|
const std::vector<unsigned char> pt{'o', 'k'};
|
|
auto env = ring.seal(pt);
|
|
if (!env.has_value()) {
|
|
return 2;
|
|
}
|
|
auto dec = ring.open(*env);
|
|
if (!dec.has_value() || dec->size() != pt.size()) {
|
|
return 3;
|
|
}
|
|
auto policy = Void::Security::PolicySnapshot::create(1, {});
|
|
if (!policy.has_value()) {
|
|
return 4;
|
|
}
|
|
const Void::Security::Principal p{.subject = "u1"};
|
|
const Void::Security::ResourceAttributes r{.resource_type = "doc"};
|
|
if (policy->authorize(p, "read", r).allowed) {
|
|
return 5;
|
|
}
|
|
return 0;
|
|
}
|