Add bitsize/bytesize trait functions.
This commit is contained in:
@@ -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() {
|
||||||
|
|||||||
@@ -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>;
|
||||||
|
|||||||
Reference in New Issue
Block a user