Skip to content

Commit

Permalink
elliptic-curve: add sec1::EncodedPoint::identity() (#408)
Browse files Browse the repository at this point in the history
Adds a convenience method for obtaining a SEC1-encoded identity point
  • Loading branch information
tarcieri authored Dec 17, 2020
1 parent 01ee4e5 commit b860d6c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions elliptic-curve/src/sec1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ where
.to_encoded_point(compress)
}

/// Return [`EncodedPoint`] representing the additive identity
/// (a.k.a. point at infinity)
pub fn identity() -> Self {
Self::from_bytes(&[0]).unwrap()
}

/// Get the length of the encoded point in bytes
pub fn len(&self) -> usize {
self.tag().message_len(C::FieldSize::to_usize())
Expand Down Expand Up @@ -647,6 +653,14 @@ mod tests {
assert_eq!(compressed_point.as_bytes(), &COMPRESSED_BYTES[..]);
}

#[test]
fn identity() {
let identity_point = EncodedPoint::identity();
assert_eq!(identity_point.tag(), Tag::Identity);
assert_eq!(identity_point.len(), 1);
assert_eq!(identity_point.as_bytes(), &IDENTITY_BYTES[..]);
}

#[cfg(feature = "alloc")]
#[test]
fn to_bytes() {
Expand Down

0 comments on commit b860d6c

Please sign in to comment.