Skip to content

Commit

Permalink
GH-2334 Simplify sizeof calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Mar 28, 2024
1 parent dd8d988 commit aaa9284
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions libraries/libfc/include/fc/crypto/bls_public_key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ namespace fc::crypto::blslib {
template<typename T>
friend T& operator<<(T& ds, const bls_public_key& sig) {
// Serialization as variable length array when it is stored as a fixed length array. This makes for easier deserialization by external tools
fc::raw::pack(ds, fc::unsigned_int(static_cast<uint32_t>(sig._affine_non_montgomery_le.size()*sizeof(uint8_t))));
ds.write(reinterpret_cast<const char*>(sig._affine_non_montgomery_le.data()), sig._affine_non_montgomery_le.size()*sizeof(uint8_t));
fc::raw::pack(ds, fc::unsigned_int(static_cast<uint32_t>(sizeof(sig._affine_non_montgomery_le))));
ds.write(reinterpret_cast<const char*>(sig._affine_non_montgomery_le.data()), sizeof(sig._affine_non_montgomery_le));
return ds;
}

Expand All @@ -66,8 +66,8 @@ namespace fc::crypto::blslib {
// Serialization as variable length array when it is stored as a fixed length array. This makes for easier deserialization by external tools
fc::unsigned_int size;
fc::raw::unpack( ds, size );
FC_ASSERT(size.value == sig._affine_non_montgomery_le.size()*sizeof(uint8_t));
ds.read(reinterpret_cast<char*>(sig._affine_non_montgomery_le.data()), sig._affine_non_montgomery_le.size()*sizeof(uint8_t));
FC_ASSERT(size.value == sizeof(sig._affine_non_montgomery_le));
ds.read(reinterpret_cast<char*>(sig._affine_non_montgomery_le.data()), sizeof(sig._affine_non_montgomery_le));
sig._jacobian_montgomery_le = from_affine_bytes_le(sig._affine_non_montgomery_le);
return ds;
}
Expand Down
16 changes: 8 additions & 8 deletions libraries/libfc/include/fc/crypto/bls_signature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ namespace fc::crypto::blslib {
template<typename T>
friend T& operator<<(T& ds, const bls_signature& sig) {
// Serialization as variable length array when it is stored as a fixed length array. This makes for easier deserialization by external tools
fc::raw::pack(ds, fc::unsigned_int(static_cast<uint32_t>(sig._affine_non_montgomery_le.size()*sizeof(uint8_t))));
ds.write(reinterpret_cast<const char*>(sig._affine_non_montgomery_le.data()), sig._affine_non_montgomery_le.size()*sizeof(uint8_t));
fc::raw::pack(ds, fc::unsigned_int(static_cast<uint32_t>(sizeof(sig._affine_non_montgomery_le))));
ds.write(reinterpret_cast<const char*>(sig._affine_non_montgomery_le.data()), sizeof(sig._affine_non_montgomery_le));
return ds;
}

Expand All @@ -58,8 +58,8 @@ namespace fc::crypto::blslib {
// Serialization as variable length array when it is stored as a fixed length array. This makes for easier deserialization by external tools
fc::unsigned_int size;
fc::raw::unpack( ds, size );
FC_ASSERT(size.value == sig._affine_non_montgomery_le.size()*sizeof(uint8_t));
ds.read(reinterpret_cast<char*>(sig._affine_non_montgomery_le.data()), sig._affine_non_montgomery_le.size()*sizeof(uint8_t));
FC_ASSERT(size.value == sizeof(sig._affine_non_montgomery_le));
ds.read(reinterpret_cast<char*>(sig._affine_non_montgomery_le.data()), sizeof(sig._affine_non_montgomery_le));
sig._jacobian_montgomery_le = to_jacobian_montgomery_le(sig._affine_non_montgomery_le);
return ds;
}
Expand Down Expand Up @@ -109,8 +109,8 @@ namespace fc::crypto::blslib {
constexpr bool raw = false;
std::array<uint8_t, 192> affine_non_montgomery_le = sig._jacobian_montgomery_le.toAffineBytesLE(raw);
// Serialization as variable length array when it is stored as a fixed length array. This makes for easier deserialization by external tools
fc::raw::pack(ds, fc::unsigned_int(static_cast<uint32_t>(affine_non_montgomery_le.size()*sizeof(uint8_t))));
ds.write(reinterpret_cast<const char*>(affine_non_montgomery_le.data()), affine_non_montgomery_le.size()*sizeof(uint8_t));
fc::raw::pack(ds, fc::unsigned_int(static_cast<uint32_t>(sizeof(affine_non_montgomery_le))));
ds.write(reinterpret_cast<const char*>(affine_non_montgomery_le.data()), sizeof(affine_non_montgomery_le));
return ds;
}

Expand All @@ -121,8 +121,8 @@ namespace fc::crypto::blslib {
fc::unsigned_int size;
fc::raw::unpack( ds, size );
std::array<uint8_t, 192> affine_non_montgomery_le;
FC_ASSERT(size.value == affine_non_montgomery_le.size()*sizeof(uint8_t));
ds.read(reinterpret_cast<char*>(affine_non_montgomery_le.data()), affine_non_montgomery_le.size()*sizeof(uint8_t));
FC_ASSERT(size.value == sizeof(affine_non_montgomery_le));
ds.read(reinterpret_cast<char*>(affine_non_montgomery_le.data()), sizeof(affine_non_montgomery_le));
sig._jacobian_montgomery_le = bls_signature::to_jacobian_montgomery_le(affine_non_montgomery_le);
return ds;
}
Expand Down

0 comments on commit aaa9284

Please sign in to comment.