From 6f33c811ef682a9c23b0134dcd2aa8b478c55231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eV=20=28=E3=8B=8E=29?= Date: Wed, 7 Nov 2018 21:22:42 +0000 Subject: [PATCH] changes to C++ wrapper to pass chromium style check (#11) --- src/wrapper.cpp | 48 +++++++ src/wrapper.hpp | 336 ++++++++++++++++++++++++++---------------------- 2 files changed, 227 insertions(+), 157 deletions(-) diff --git a/src/wrapper.cpp b/src/wrapper.cpp index d42c9c2..a8313d9 100644 --- a/src/wrapper.cpp +++ b/src/wrapper.cpp @@ -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) { @@ -20,6 +25,9 @@ namespace challenge_bypass_ristretto { // class TokenPreimage namespace challenge_bypass_ristretto { + TokenPreimage::TokenPreimage(std::shared_ptr raw) : raw(raw) {} + TokenPreimage::TokenPreimage(const TokenPreimage& other) = default; + TokenPreimage::~TokenPreimage() {} TokenPreimage TokenPreimage::decode_base64(const std::string encoded) { std::shared_ptr raw_preimage(token_preimage_decode_base64(encoded.c_str()), token_preimage_destroy); @@ -39,6 +47,10 @@ namespace challenge_bypass_ristretto { // class Token namespace challenge_bypass_ristretto { + Token::Token(std::shared_ptr raw) : raw(raw) {} + Token::Token(const Token& other) = default; + Token::~Token() {} + Token Token::random() { std::shared_ptr raw_token(token_random(), token_destroy); if (raw_token == nullptr) { @@ -83,6 +95,10 @@ namespace challenge_bypass_ristretto { // class BlindedToken namespace challenge_bypass_ristretto { + BlindedToken::BlindedToken(std::shared_ptr raw) : raw(raw) {} + BlindedToken::BlindedToken(const BlindedToken& other) = default; + BlindedToken::~BlindedToken() { } + BlindedToken BlindedToken::decode_base64(const std::string encoded) { std::shared_ptr raw_blinded(blinded_token_decode_base64(encoded.c_str()), blinded_token_destroy); if (raw_blinded == nullptr) { @@ -101,6 +117,10 @@ namespace challenge_bypass_ristretto { // class SignedToken namespace challenge_bypass_ristretto { + SignedToken::SignedToken(std::shared_ptr raw) : raw(raw) {} + SignedToken::SignedToken(const SignedToken& other) = default; + SignedToken::~SignedToken() {} + SignedToken SignedToken::decode_base64(const std::string encoded) { std::shared_ptr raw_signed(signed_token_decode_base64(encoded.c_str()), signed_token_destroy); if (raw_signed == nullptr) { @@ -119,6 +139,10 @@ namespace challenge_bypass_ristretto { // class VerificationSignature namespace challenge_bypass_ristretto { + VerificationSignature::VerificationSignature(std::shared_ptr raw) : raw(raw) {} + VerificationSignature::VerificationSignature(const VerificationSignature& other) = default; + VerificationSignature::~VerificationSignature() {} + VerificationSignature VerificationSignature::decode_base64(const std::string encoded) { std::shared_ptr raw_sig(verification_signature_decode_base64(encoded.c_str()), verification_signature_destroy); if (raw_sig == nullptr) { @@ -137,6 +161,10 @@ namespace challenge_bypass_ristretto { // class UnblindedToken namespace challenge_bypass_ristretto { + UnblindedToken::UnblindedToken(std::shared_ptr raw) : raw(raw) {} + UnblindedToken::UnblindedToken(const UnblindedToken& other) = default; + UnblindedToken::~UnblindedToken() {} + VerificationKey UnblindedToken::derive_verification_key() { return VerificationKey(std::shared_ptr(unblinded_token_derive_verification_key_sha512(raw.get()), verification_key_destroy)); } @@ -163,6 +191,10 @@ namespace challenge_bypass_ristretto { // class VerificationKey namespace challenge_bypass_ristretto { + VerificationKey::VerificationKey(std::shared_ptr raw) : raw(raw) {} + VerificationKey::VerificationKey(const VerificationKey& other) = default; + VerificationKey::~VerificationKey() {} + VerificationSignature VerificationKey::sign(const std::string message) { std::shared_ptr raw_verification_signature(verification_key_sign_sha512(raw.get(), message.c_str()), verification_signature_destroy); if (raw_verification_signature == nullptr) { @@ -182,6 +214,10 @@ namespace challenge_bypass_ristretto { // class SigningKey namespace challenge_bypass_ristretto { + SigningKey::SigningKey(std::shared_ptr raw) : raw(raw) {} + SigningKey::SigningKey(const SigningKey& other) = default; + SigningKey::~SigningKey() {} + SigningKey SigningKey::random() { std::shared_ptr raw_key(signing_key_random(), signing_key_destroy); if (raw_key == nullptr) { @@ -225,6 +261,10 @@ namespace challenge_bypass_ristretto { // class PublicKey namespace challenge_bypass_ristretto { + PublicKey::PublicKey(std::shared_ptr raw) : raw(raw) {} + PublicKey::PublicKey(const PublicKey& other) = default; + PublicKey::~PublicKey() {} + PublicKey PublicKey::decode_base64(const std::string encoded) { std::shared_ptr raw_key(public_key_decode_base64(encoded.c_str()), public_key_destroy); if (raw_key == nullptr) { @@ -243,6 +283,10 @@ namespace challenge_bypass_ristretto { // class DLEQProof namespace challenge_bypass_ristretto { + DLEQProof::DLEQProof(std::shared_ptr 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(dleq_proof_new(blinded_token.raw.get(), signed_token.raw.get(), key.raw.get()), dleq_proof_destroy); if (raw == nullptr) { @@ -276,6 +320,10 @@ namespace challenge_bypass_ristretto { // class BatchDLEQProof namespace challenge_bypass_ristretto { + BatchDLEQProof::BatchDLEQProof(std::shared_ptr raw) : raw(raw) {} + BatchDLEQProof::BatchDLEQProof(const BatchDLEQProof& other) = default; + BatchDLEQProof::~BatchDLEQProof() {} + BatchDLEQProof::BatchDLEQProof(std::vector blinded_tokens, std::vector signed_tokens, SigningKey key) { if (blinded_tokens.size() != signed_tokens.size()) { throw TokenException("Blinded tokens and signed tokens must have the same length"); diff --git a/src/wrapper.hpp b/src/wrapper.hpp index 637922d..99d2f1f 100644 --- a/src/wrapper.hpp +++ b/src/wrapper.hpp @@ -1,168 +1,190 @@ #ifndef _CHALLENGE_BYPASS_RISTRETTO_WRAPPER_HPP #define _CHALLENGE_BYPASS_RISTRETTO_WRAPPER_HPP - -#include -#include -#include +#include +#include +#include extern "C" { #include "lib.h" } namespace challenge_bypass_ristretto { - class TokenException : std::exception { - public: - TokenException(const std::string& msg) : msg(msg){}; - static TokenException last_error(std::string msg); - const char * what () const throw () { - return msg.c_str(); - } - - private: - std::string msg; - }; - - class TokenPreimage { - friend class SigningKey; - - public: - TokenPreimage(std::shared_ptr raw) : raw(raw){} - static TokenPreimage decode_base64(const std::string); - std::string encode_base64(); - - private: - std::shared_ptr raw; - }; - - class BlindedToken { - friend class SigningKey; - friend class DLEQProof; - friend class BatchDLEQProof; - - public: - BlindedToken(std::shared_ptr raw) : raw(raw){} - static BlindedToken decode_base64(const std::string); - std::string encode_base64(); - - private: - std::shared_ptr raw; - }; - - class SignedToken { - friend class Token; - friend class DLEQProof; - friend class BatchDLEQProof; - - public: - SignedToken(std::shared_ptr raw) : raw(raw){} - static SignedToken decode_base64(const std::string); - std::string encode_base64(); - - private: - std::shared_ptr raw; - }; - - class VerificationSignature { - friend class VerificationKey; - - public: - VerificationSignature(std::shared_ptr raw) : raw(raw){} - static VerificationSignature decode_base64(const std::string); - std::string encode_base64(); - - private: - std::shared_ptr raw; - }; - - class VerificationKey { - public: - VerificationKey(std::shared_ptr raw) : raw(raw){} - VerificationSignature sign(const std::string); - bool verify(VerificationSignature, const std::string); - - private: - std::shared_ptr raw; - }; - - class UnblindedToken { - public: - UnblindedToken(std::shared_ptr raw) : raw(raw){} - VerificationKey derive_verification_key(); - TokenPreimage preimage(); - static UnblindedToken decode_base64(const std::string); - std::string encode_base64(); - - private: - std::shared_ptr raw; - }; - - class Token { - public: - Token(std::shared_ptr raw) : raw(raw){} - static Token random(); - BlindedToken blind(); - UnblindedToken unblind(SignedToken); - static Token decode_base64(const std::string); - std::string encode_base64(); - - private: - std::shared_ptr raw; - }; - - class PublicKey { - friend class DLEQProof; - friend class BatchDLEQProof; - - public: - PublicKey(std::shared_ptr raw) : raw(raw){} - static PublicKey decode_base64(const std::string); - std::string encode_base64(); - - private: - std::shared_ptr raw; - }; - - class SigningKey { - friend class DLEQProof; - friend class BatchDLEQProof; - - public: - SigningKey(std::shared_ptr raw) : raw(raw){} - static SigningKey random(); - SignedToken sign(BlindedToken); - UnblindedToken rederive_unblinded_token(TokenPreimage); - PublicKey public_key(); - static SigningKey decode_base64(const std::string); - std::string encode_base64(); - - private: - std::shared_ptr raw; - }; - - class DLEQProof { - public: - DLEQProof(std::shared_ptr raw) : raw(raw){} - DLEQProof(BlindedToken, SignedToken, SigningKey); - bool verify(BlindedToken, SignedToken, PublicKey); - static DLEQProof decode_base64(const std::string); - std::string encode_base64(); - - private: - std::shared_ptr raw; - }; - - class BatchDLEQProof { - public: - BatchDLEQProof(std::shared_ptr raw) : raw(raw){} - BatchDLEQProof(std::vector, std::vector, SigningKey); - bool verify(std::vector, std::vector, PublicKey); - static BatchDLEQProof decode_base64(const std::string); - std::string encode_base64(); - - private: - std::shared_ptr raw; - }; -} +class TokenException : std::exception { + public: + TokenException(const std::string&); + ~TokenException() override; + const char* what() const throw() override; + static TokenException last_error(std::string msg); + + private: + std::string msg; +}; + +class TokenPreimage { + friend class SigningKey; + + public: + TokenPreimage(std::shared_ptr); + TokenPreimage(const TokenPreimage&); + ~TokenPreimage(); + static TokenPreimage decode_base64(const std::string); + std::string encode_base64(); + + private: + std::shared_ptr raw; +}; + +class BlindedToken { + friend class SigningKey; + friend class DLEQProof; + friend class BatchDLEQProof; + + public: + BlindedToken(std::shared_ptr); + BlindedToken(const BlindedToken&); + ~BlindedToken(); + static BlindedToken decode_base64(const std::string); + std::string encode_base64(); + + private: + std::shared_ptr raw; +}; + +class SignedToken { + friend class Token; + friend class DLEQProof; + friend class BatchDLEQProof; + + public: + SignedToken(std::shared_ptr); + SignedToken(const SignedToken&); + ~SignedToken(); + static SignedToken decode_base64(const std::string); + std::string encode_base64(); + + private: + std::shared_ptr raw; +}; + +class VerificationSignature { + friend class VerificationKey; + + public: + VerificationSignature(std::shared_ptr); + VerificationSignature(const VerificationSignature&); + ~VerificationSignature(); + static VerificationSignature decode_base64(const std::string); + std::string encode_base64(); + + private: + std::shared_ptr raw; +}; + +class VerificationKey { + public: + VerificationKey(std::shared_ptr); + VerificationKey(const VerificationKey&); + ~VerificationKey(); + VerificationSignature sign(const std::string); + bool verify(VerificationSignature, const std::string); + + private: + std::shared_ptr raw; +}; + +class UnblindedToken { + public: + UnblindedToken(std::shared_ptr); + UnblindedToken(const UnblindedToken&); + ~UnblindedToken(); + VerificationKey derive_verification_key(); + TokenPreimage preimage(); + static UnblindedToken decode_base64(const std::string); + std::string encode_base64(); + + private: + std::shared_ptr raw; +}; + +class Token { + public: + Token(std::shared_ptr); + Token(const Token&); + ~Token(); + static Token random(); + BlindedToken blind(); + UnblindedToken unblind(SignedToken); + static Token decode_base64(const std::string); + std::string encode_base64(); + + private: + std::shared_ptr raw; +}; + +class PublicKey { + friend class DLEQProof; + friend class BatchDLEQProof; + + public: + PublicKey(std::shared_ptr); + PublicKey(const PublicKey&); + ~PublicKey(); + static PublicKey decode_base64(const std::string); + std::string encode_base64(); + + private: + std::shared_ptr raw; +}; + +class SigningKey { + friend class DLEQProof; + friend class BatchDLEQProof; + + public: + SigningKey(std::shared_ptr); + SigningKey(const SigningKey&); + ~SigningKey(); + static SigningKey random(); + SignedToken sign(BlindedToken); + UnblindedToken rederive_unblinded_token(TokenPreimage); + PublicKey public_key(); + static SigningKey decode_base64(const std::string); + std::string encode_base64(); + + private: + std::shared_ptr raw; +}; + +class DLEQProof { + public: + DLEQProof(std::shared_ptr); + DLEQProof(const DLEQProof&); + DLEQProof(BlindedToken, SignedToken, SigningKey); + ~DLEQProof(); + bool verify(BlindedToken, SignedToken, PublicKey); + static DLEQProof decode_base64(const std::string); + std::string encode_base64(); + + private: + std::shared_ptr raw; +}; + +class BatchDLEQProof { + public: + BatchDLEQProof(std::shared_ptr); + BatchDLEQProof(const BatchDLEQProof&); + BatchDLEQProof(std::vector, + std::vector, + SigningKey); + ~BatchDLEQProof(); + bool verify(std::vector, std::vector, PublicKey); + static BatchDLEQProof decode_base64(const std::string); + std::string encode_base64(); + + private: + std::shared_ptr raw; +}; +} // namespace challenge_bypass_ristretto #endif /* _CHALLENGE_BYPASS_RISTRETTO_WRAPPER_HPP */