Add bitsize/bytesize trait functions.

This commit is contained in:
2018-03-11 15:34:18 -07:00
parent 716a165007
commit 0698272b2c
2 changed files with 12 additions and 0 deletions

View File

@@ -259,6 +259,14 @@ macro_rules! construct_unsigned {
impl CryptoNumSerialization for $type { impl CryptoNumSerialization for $type {
fn bit_size(&self) -> usize {
$count * 64
}
fn byte_size(&self) -> usize {
$count * 8
}
fn to_bytes(&self) -> Vec<u8> { fn to_bytes(&self) -> Vec<u8> {
let mut res = Vec::with_capacity($count * 8); let mut res = Vec::with_capacity($count * 8);
for x in self.contents.iter() { for x in self.contents.iter() {

View File

@@ -32,6 +32,10 @@ pub trait CryptoNumBase {
} }
pub trait CryptoNumSerialization { 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 /// Convert a number to a series of bytes, in standard order (most to
/// least significant) /// least significant)
fn to_bytes(&self) -> Vec<u8>; fn to_bytes(&self) -> Vec<u8>;