mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-02 04:03:35 +00:00
add serialize_uncompressed to GenericSignature
This commit is contained in:
@@ -14,6 +14,9 @@ use tree_hash::TreeHash;
|
||||
/// The byte-length of a BLS signature when serialized in compressed form.
|
||||
pub const SIGNATURE_BYTES_LEN: usize = 96;
|
||||
|
||||
/// The byte-length of a BLS signature when serialized in uncompressed form.
|
||||
pub const SIGNATURE_UNCOMPRESSED_BYTES_LEN: usize = 192;
|
||||
|
||||
/// Represents the signature at infinity.
|
||||
pub const INFINITY_SIGNATURE: [u8; SIGNATURE_BYTES_LEN] = [
|
||||
0xc0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@@ -31,6 +34,9 @@ pub trait TSignature<GenericPublicKey>: Sized + Clone {
|
||||
/// Serialize `self` as compressed bytes.
|
||||
fn serialize(&self) -> [u8; SIGNATURE_BYTES_LEN];
|
||||
|
||||
/// Serialize `self` as uncompressed bytes.
|
||||
fn serialize_uncompressed(&self) -> [u8; SIGNATURE_UNCOMPRESSED_BYTES_LEN];
|
||||
|
||||
/// Deserialize `self` from compressed bytes.
|
||||
fn deserialize(bytes: &[u8]) -> Result<Self, Error>;
|
||||
|
||||
@@ -115,6 +121,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Serialize `self` as compressed bytes.
|
||||
pub fn serialize_uncompressed(&self) -> Option<[u8; SIGNATURE_UNCOMPRESSED_BYTES_LEN]> {
|
||||
self.point.as_ref().map(|point| point.serialize_uncompressed())
|
||||
}
|
||||
|
||||
/// Deserialize `self` from compressed bytes.
|
||||
pub fn deserialize(bytes: &[u8]) -> Result<Self, Error> {
|
||||
let point = if bytes == &NONE_SIGNATURE[..] {
|
||||
|
||||
Reference in New Issue
Block a user