diff --git a/src/cryptonum/builder.rs b/src/cryptonum/builder.rs index 5ef94dc..ff5a622 100644 --- a/src/cryptonum/builder.rs +++ b/src/cryptonum/builder.rs @@ -259,6 +259,14 @@ macro_rules! construct_unsigned { impl CryptoNumSerialization for $type { + fn bit_size(&self) -> usize { + $count * 64 + } + + fn byte_size(&self) -> usize { + $count * 8 + } + fn to_bytes(&self) -> Vec { let mut res = Vec::with_capacity($count * 8); for x in self.contents.iter() { diff --git a/src/cryptonum/traits.rs b/src/cryptonum/traits.rs index 4209c39..9a16888 100644 --- a/src/cryptonum/traits.rs +++ b/src/cryptonum/traits.rs @@ -32,6 +32,10 @@ pub trait CryptoNumBase { } pub trait CryptoNumSerialization { + /// The number of bits used when this number is serialized. + fn bit_size(&self) -> usize; + /// The number of bytes used when this number is serialized. + fn byte_size(&self) -> usize; /// Convert a number to a series of bytes, in standard order (most to /// least significant) fn to_bytes(&self) -> Vec;