Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions elliptic-curve/src/sec1.rs
Original file line numberDiff line numberDiff 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 DownExpand 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