Skip to content

Commit

Permalink
changes to C++ wrapper to pass chromium style check (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
evq committed Nov 7, 2018
1 parent c7c6980 commit 6f33c81
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 157 deletions.
48 changes: 48 additions & 0 deletions src/wrapper.cpp
Expand Up @@ -6,6 +6,11 @@ extern "C" {

// class TokenException
namespace challenge_bypass_ristretto {
TokenException::TokenException(const std::string& msg) : msg(msg){}
TokenException::~TokenException() {}

const char* TokenException::what() const throw() { return msg.c_str(); }

TokenException TokenException::last_error(std::string default_msg) {
char* tmp = last_error_message();
if (tmp != nullptr) {
Expand All @@ -20,6 +25,9 @@ namespace challenge_bypass_ristretto {

// class TokenPreimage
namespace challenge_bypass_ristretto {
TokenPreimage::TokenPreimage(std::shared_ptr<C_TokenPreimage> raw) : raw(raw) {}
TokenPreimage::TokenPreimage(const TokenPreimage& other) = default;
TokenPreimage::~TokenPreimage() {}

TokenPreimage TokenPreimage::decode_base64(const std::string encoded) {
std::shared_ptr<C_TokenPreimage> raw_preimage(token_preimage_decode_base64(encoded.c_str()), token_preimage_destroy);
Expand All @@ -39,6 +47,10 @@ namespace challenge_bypass_ristretto {

// class Token
namespace challenge_bypass_ristretto {
Token::Token(std::shared_ptr<C_Token> raw) : raw(raw) {}
Token::Token(const Token& other) = default;
Token::~Token() {}

Token Token::random() {
std::shared_ptr<C_Token> raw_token(token_random(), token_destroy);
if (raw_token == nullptr) {
Expand Down Expand Up @@ -83,6 +95,10 @@ namespace challenge_bypass_ristretto {

// class BlindedToken
namespace challenge_bypass_ristretto {
BlindedToken::BlindedToken(std::shared_ptr<C_BlindedToken> raw) : raw(raw) {}
BlindedToken::BlindedToken(const BlindedToken& other) = default;
BlindedToken::~BlindedToken() { }

BlindedToken BlindedToken::decode_base64(const std::string encoded) {
std::shared_ptr<C_BlindedToken> raw_blinded(blinded_token_decode_base64(encoded.c_str()), blinded_token_destroy);
if (raw_blinded == nullptr) {
Expand All @@ -101,6 +117,10 @@ namespace challenge_bypass_ristretto {

// class SignedToken
namespace challenge_bypass_ristretto {
SignedToken::SignedToken(std::shared_ptr<C_SignedToken> raw) : raw(raw) {}
SignedToken::SignedToken(const SignedToken& other) = default;
SignedToken::~SignedToken() {}

SignedToken SignedToken::decode_base64(const std::string encoded) {
std::shared_ptr<C_SignedToken> raw_signed(signed_token_decode_base64(encoded.c_str()), signed_token_destroy);
if (raw_signed == nullptr) {
Expand All @@ -119,6 +139,10 @@ namespace challenge_bypass_ristretto {

// class VerificationSignature
namespace challenge_bypass_ristretto {
VerificationSignature::VerificationSignature(std::shared_ptr<C_VerificationSignature> raw) : raw(raw) {}
VerificationSignature::VerificationSignature(const VerificationSignature& other) = default;
VerificationSignature::~VerificationSignature() {}

VerificationSignature VerificationSignature::decode_base64(const std::string encoded) {
std::shared_ptr<C_VerificationSignature> raw_sig(verification_signature_decode_base64(encoded.c_str()), verification_signature_destroy);
if (raw_sig == nullptr) {
Expand All @@ -137,6 +161,10 @@ namespace challenge_bypass_ristretto {

// class UnblindedToken
namespace challenge_bypass_ristretto {
UnblindedToken::UnblindedToken(std::shared_ptr<C_UnblindedToken> raw) : raw(raw) {}
UnblindedToken::UnblindedToken(const UnblindedToken& other) = default;
UnblindedToken::~UnblindedToken() {}

VerificationKey UnblindedToken::derive_verification_key() {
return VerificationKey(std::shared_ptr<C_VerificationKey>(unblinded_token_derive_verification_key_sha512(raw.get()), verification_key_destroy));
}
Expand All @@ -163,6 +191,10 @@ namespace challenge_bypass_ristretto {

// class VerificationKey
namespace challenge_bypass_ristretto {
VerificationKey::VerificationKey(std::shared_ptr<C_VerificationKey> raw) : raw(raw) {}
VerificationKey::VerificationKey(const VerificationKey& other) = default;
VerificationKey::~VerificationKey() {}

VerificationSignature VerificationKey::sign(const std::string message) {
std::shared_ptr<C_VerificationSignature> raw_verification_signature(verification_key_sign_sha512(raw.get(), message.c_str()), verification_signature_destroy);
if (raw_verification_signature == nullptr) {
Expand All @@ -182,6 +214,10 @@ namespace challenge_bypass_ristretto {

// class SigningKey
namespace challenge_bypass_ristretto {
SigningKey::SigningKey(std::shared_ptr<C_SigningKey> raw) : raw(raw) {}
SigningKey::SigningKey(const SigningKey& other) = default;
SigningKey::~SigningKey() {}

SigningKey SigningKey::random() {
std::shared_ptr<C_SigningKey> raw_key(signing_key_random(), signing_key_destroy);
if (raw_key == nullptr) {
Expand Down Expand Up @@ -225,6 +261,10 @@ namespace challenge_bypass_ristretto {

// class PublicKey
namespace challenge_bypass_ristretto {
PublicKey::PublicKey(std::shared_ptr<C_PublicKey> raw) : raw(raw) {}
PublicKey::PublicKey(const PublicKey& other) = default;
PublicKey::~PublicKey() {}

PublicKey PublicKey::decode_base64(const std::string encoded) {
std::shared_ptr<C_PublicKey> raw_key(public_key_decode_base64(encoded.c_str()), public_key_destroy);
if (raw_key == nullptr) {
Expand All @@ -243,6 +283,10 @@ namespace challenge_bypass_ristretto {

// class DLEQProof
namespace challenge_bypass_ristretto {
DLEQProof::DLEQProof(std::shared_ptr<C_DLEQProof> raw) : raw(raw) {}
DLEQProof::DLEQProof(const DLEQProof& other) = default;
DLEQProof::~DLEQProof() {}

DLEQProof::DLEQProof(BlindedToken blinded_token, SignedToken signed_token, SigningKey key) {
raw = std::shared_ptr<C_DLEQProof>(dleq_proof_new(blinded_token.raw.get(), signed_token.raw.get(), key.raw.get()), dleq_proof_destroy);
if (raw == nullptr) {
Expand Down Expand Up @@ -276,6 +320,10 @@ namespace challenge_bypass_ristretto {

// class BatchDLEQProof
namespace challenge_bypass_ristretto {
BatchDLEQProof::BatchDLEQProof(std::shared_ptr<C_BatchDLEQProof> raw) : raw(raw) {}
BatchDLEQProof::BatchDLEQProof(const BatchDLEQProof& other) = default;
BatchDLEQProof::~BatchDLEQProof() {}

BatchDLEQProof::BatchDLEQProof(std::vector<BlindedToken> blinded_tokens, std::vector<SignedToken> signed_tokens, SigningKey key) {
if (blinded_tokens.size() != signed_tokens.size()) {
throw TokenException("Blinded tokens and signed tokens must have the same length");
Expand Down

0 comments on commit 6f33c81

Please sign in to comment.