Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
elliptic_webauthn.hpp
Go to the documentation of this file.
1#pragma once
7#include <fc/fwd.hpp>
8#include <fc/array.hpp>
9#include <fc/io/raw_fwd.hpp>
10
11namespace fc { namespace crypto { namespace webauthn {
12
13class signature;
14
16 public:
18
19 //Used for base58 de/serialization
21 public_key serialize() const { return *this; }
22
28
29 bool valid() const { return rpid.size(); }
30
32 public_key(const public_key_data_type& p, const user_presence_t& t, const std::string& s) :
33 public_key_data(p), user_verification_type(t), rpid(s) {
34 post_init();
35 }
36 public_key(const signature& c, const fc::sha256& digest, bool check_canonical = true);
37
38 bool operator==(const public_key& o) const {
39 return public_key_data == o.public_key_data &&
40 user_verification_type == o.user_verification_type &&
41 rpid == o.rpid;
42 }
43 bool operator<(const public_key& o) const {
44 return std::tie(public_key_data, user_verification_type, rpid) < std::tie(o.public_key_data, o.user_verification_type, o.rpid);
45 }
46
47 template<typename Stream>
48 friend Stream& operator<<(Stream& ds, const public_key& k) {
49 fc::raw::pack(ds, k.public_key_data);
50 fc::raw::pack(ds, static_cast<uint8_t>(k.user_verification_type));
51 fc::raw::pack(ds, k.rpid);
52 return ds;
53 }
54
55 template<typename Stream>
57 fc::raw::unpack(ds, k.public_key_data);
58 uint8_t t;
59 fc::raw::unpack(ds, t);
60 k.user_verification_type = static_cast<user_presence_t>(t);
61 fc::raw::unpack(ds, k.rpid);
62 k.post_init();
63 return ds;
64 }
65
66 private:
67 public_key_data_type public_key_data;
69 std::string rpid;
70
71 void post_init();
72};
73
74class signature {
75 public:
76 //used for base58 de/serialization
78 signature serialize()const { return *this; }
79
81 signature(const fc::crypto::r1::compact_signature& s, const std::vector<uint8_t>& a, const std::string& j) :
82 compact_signature(s), auth_data(a), client_json(j) {}
83
84 public_key recover(const sha256& digest, bool check_canonical) const {
85 return public_key(*this, digest, check_canonical);
86 }
87
88 size_t variable_size() const {
89 return auth_data.size() + client_json.size();
90 }
91
92 bool operator==(const signature& o) const {
93 return compact_signature == o.compact_signature &&
94 auth_data == o.auth_data &&
95 client_json == o.client_json;
96 }
97
98 bool operator<(const signature& o) const {
99 return std::tie(compact_signature, auth_data, client_json) < std::tie(o.compact_signature, o.auth_data, o.client_json);
100 }
101
102 //for container usage
103 size_t get_hash() const {
104 return *(size_t*)&compact_signature.data[32-sizeof(size_t)] + *(size_t*)&compact_signature.data[64-sizeof(size_t)];
105 }
106
107 friend struct fc::reflector<signature>;
108 friend class public_key;
109 private:
110 fc::crypto::r1::compact_signature compact_signature;
111 std::vector<uint8_t> auth_data;
112 std::string client_json;
113};
114
115}
116
117template<>
118struct eq_comparator<webauthn::signature> {
119 static bool apply(const webauthn::signature& a, const webauthn::signature& b) {
120 return a == b;
121 }
122};
123
124template<>
125struct less_comparator<webauthn::signature> {
126 static bool apply(const webauthn::signature& a, const webauthn::signature& b) {
127 return a < b;
128 }
129};
130
131template<>
132struct eq_comparator<webauthn::public_key> {
133 static bool apply(const webauthn::public_key& a, const webauthn::public_key& b) {
134 return a == b;
135 }
136};
137
138template<>
139struct less_comparator<webauthn::public_key> {
140 static bool apply(const webauthn::public_key& a, const webauthn::public_key& b) {
141 return a < b;
142 }
143};
144
145}}
146#include <fc/reflect/reflect.hpp>
147
148FC_REFLECT(fc::crypto::webauthn::signature, (compact_signature)(auth_data)(client_json))
const mie::Vuint & p
Definition bn.cpp:27
T data[N]
Definition array.hpp:37
public_key(const public_key_data_type &p, const user_presence_t &t, const std::string &s)
friend Stream & operator<<(Stream &ds, const public_key &k)
friend Stream & operator>>(Stream &ds, public_key &k)
fc::array< char, 33 > public_key_data_type
bool operator<(const public_key &o) const
bool operator==(const public_key &o) const
public_key recover(const sha256 &digest, bool check_canonical) const
bool operator<(const signature &o) const
bool operator==(const signature &o) const
signature(const fc::crypto::r1::compact_signature &s, const std::vector< uint8_t > &a, const std::string &j)
Concept for reading and writing characters.
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
namespace sysio::chain
Definition authority.cpp:3
fc::sha256 digest(const T &value)
Definition digest.hpp:9
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition reflect.hpp:311
unsigned char uint8_t
Definition stdint.h:124
static bool apply(const webauthn::public_key &a, const webauthn::public_key &b)
static bool apply(const webauthn::signature &a, const webauthn::signature &b)
static bool apply(const webauthn::public_key &a, const webauthn::public_key &b)
static bool apply(const webauthn::signature &a, const webauthn::signature &b)
defines visit functions for T Unless this is specialized, visit() will not be defined for T.
Definition reflect.hpp:33
char * s
uint16_t j