1
0
forked from cheng/wallet

struggling because with the new update, stuff just stopped working

This commit is contained in:
Cheng 2022-10-05 15:34:55 +11:00
parent 9a349fcdf9
commit fab225e872
No known key found for this signature in database
GPG Key ID: D51301E176B31828

View File

@ -146,10 +146,11 @@ namespace ro {
// template class that generates a std::span of bytes over the blob // template class that generates a std::span of bytes over the blob
// field of any object containing a blob record, which is normally sufficient // field of any object containing a blob record, which is normally sufficient
// for a machine independent representation of that object // for a machine independent representation of that object
template < template <typename T>
typename T, std::enable_if_t<
decltype(std::size(std::declval<T>().blob)) dummy_arg = 0 is_blob_field_type<T>::value,
> auto serialize(const T& pt) { std::span<const byte>
> serialize(const T& pt) {
return serialize(pt.blob); return serialize(pt.blob);
} }
@ -182,17 +183,17 @@ namespace ro {
template<class T, std::enable_if_t<is_standard_unsigned_integer<T>, int> = 0> template<class T, std::enable_if_t<is_standard_unsigned_integer<T>, int> = 0>
class userial : public std::span<byte> { class userial : public std::span<byte> {
public: public:
std::array<byte, (std::numeric_limits<T>::digits + 6) / 7> blob; std::array<byte, (std::numeric_limits<T>::digits + 6) / 7> bblob;
userial(T i) { userial(T i) {
byte* p = &blob[0] + sizeof(blob); byte* p = &bblob[0] + sizeof(bblob);
*(--p) = i & 0x7f; *(--p) = i & 0x7f;
i >>= 7; i >>= 7;
while (i != 0) { while (i != 0) {
*(--p) = (i & 0x7f) | 0x80; *(--p) = (i & 0x7f) | 0x80;
i >>= 7; i >>= 7;
} }
assert(p >= &blob[0]); assert(p >= &bblob[0]);
*static_cast<std::span<byte>*>(this) = std::span<byte>(p, &blob[0] + sizeof(blob));; *static_cast<std::span<byte>*>(this) = std::span<byte>(p, &bblob[0] + sizeof(bblob));;
} }
}; };
@ -200,10 +201,10 @@ namespace ro {
template<class T, std::enable_if_t<is_standard_signed_integer<T>, int> = 0> template<class T, std::enable_if_t<is_standard_signed_integer<T>, int> = 0>
class iserial : public std::span<byte> { class iserial : public std::span<byte> {
public: public:
std::array<byte, (std::numeric_limits<T>::digits + 7) / 7> blob; std::array<byte, (std::numeric_limits<T>::digits + 7) / 7> bblob;
iserial(T i) { iserial(T i) {
// Throw away the repeated leading bits, and g // Throw away the repeated leading bits, and g
byte* p = &blob[0] + sizeof(blob); byte* p = &bblob[0] + sizeof(bblob);
unsigned count; unsigned count;
if (i < 0) { if (i < 0) {
size_t ui = i; size_t ui = i;
@ -218,8 +219,8 @@ namespace ro {
i >>= 7; i >>= 7;
*(--p) = (i & 0x7f) | 0x80; *(--p) = (i & 0x7f) | 0x80;
} }
assert(p >= &blob[0]); assert(p >= &bblob[0]);
*static_cast<std::span<byte>*>(this) = std::span<byte>(p, &blob[0] + sizeof(blob));; *static_cast<std::span<byte>*>(this) = std::span<byte>(p, &bblob[0] + sizeof(bblob));;
} }
}; };
@ -462,13 +463,6 @@ namespace ristretto255 {
} }
} }
template < typename T>
decltype(ro::serialize(std::declval<std::remove_cvref<T>::type >()), hsh<hashsize>())&
operator <<(const T & j) {
return *this << ro::serialize(j);
}
template<typename T, typename... Args, template<typename T, typename... Args,
typename std::enable_if< ro::is_serializable<const T>::value, int >::type dummy_arg = 0 typename std::enable_if< ro::is_serializable<const T>::value, int >::type dummy_arg = 0
> void hashinto(const T first, Args... args) { > void hashinto(const T first, Args... args) {
@ -477,27 +471,45 @@ namespace ristretto255 {
(*this).hashinto(args...); (*this).hashinto(args...);
} }
} }
};
hsh<hashsize>& operator <<(const std::span<const byte> j) { template<unsigned int hashsize, typename T>
ristretto255::hsh<hashsize>& operator <<(ristretto255::hsh<hashsize> u, const T& j) {
if constexpr (std::is_same_v<std::remove_cvref_t<T>, std::span<const byte> >) {
int i = crypto_generichash_blake2b_update( int i = crypto_generichash_blake2b_update(
&st, &u.st,
&j[0], &j[0],
j.size() j.size()
); );
if (i) throw HashReuseException(); if (i) throw HashReuseException();
return *this; return u;
}
else if constexpr (std::is_same_v<std::remove_cvref_t<T>, const char*>) {
int i = crypto_generichash_blake2b_update(
&u.st,
(const unsigned char *)(j),
strlen(j) + 1
);
if (i) throw HashReuseException();
return u;
}
else {
return u << ro::serialize(j);
}
} }
hsh<hashsize>& operator <<(char* sz) { template<unsigned int hashsize, const char *>
ristretto255::hsh<hashsize>& operator <<(ristretto255::hsh<hashsize> u, const char* sz) {
int i = crypto_generichash_blake2b_update( int i = crypto_generichash_blake2b_update(
&st, &u.st,
static_cast<std::nullptr_t>(sz), static_cast<std::nullptr_t>(sz),
// (unsigned char*)(sz),
strlen(sz) + 1 strlen(sz) + 1
); );
if (i) throw HashReuseException(); if (i) throw HashReuseException();
return *this; return u;
} }
};
// This constructs a finalized hash. // This constructs a finalized hash.
// If it has one argument, and that argument is hsh (unfinalized hash) object, // If it has one argument, and that argument is hsh (unfinalized hash) object,