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