Commit 0de171f 1 parent f5a1e7d commit 0de171f Copy full SHA for 0de171f
File tree 4 files changed +19
-1
lines changed
4 files changed +19
-1
lines changed Original file line number Diff line number Diff line change
1
+ ## v0.4.3
2
+ * Add ` Point::serialized_len `
3
+
1
4
## v0.4.2
2
5
* Update links, add info about our discord [ #44 ]
3
6
Original file line number Diff line number Diff line change 1
1
[package ]
2
2
name = " generic-ec"
3
- version = " 0.4.2 "
3
+ version = " 0.4.3 "
4
4
edition = " 2021"
5
5
license = " MIT OR Apache-2.0"
6
6
repository = " https://github.com/LFDT-Lockness/generic-ec"
Original file line number Diff line number Diff line change @@ -97,6 +97,19 @@ impl<E: Curve> Point<E> {
97
97
. and_then ( Self :: try_from_raw)
98
98
. ok_or ( InvalidPoint )
99
99
}
100
+
101
+ /// Returns size of bytes buffer that can fit a serialized point
102
+ ///
103
+ /// `compressed` parameter has the same meaning as for [`Point::to_bytes`]; a
104
+ /// buffer created with length of `Point::serialized_len(compress)` would fit
105
+ /// exactly the serialization `p.to_bytes(compress)`.
106
+ pub fn serialized_len ( compressed : bool ) -> usize {
107
+ if compressed {
108
+ E :: CompressedPointArray :: zeroes ( ) . as_ref ( ) . len ( )
109
+ } else {
110
+ E :: UncompressedPointArray :: zeroes ( ) . as_ref ( ) . len ( )
111
+ }
112
+ }
100
113
}
101
114
102
115
impl < E : Curve > TryFromRaw for Point < E > {
Original file line number Diff line number Diff line change @@ -110,6 +110,8 @@ mod tests {
110
110
let bytes_compressed = point. to_bytes ( true ) ;
111
111
let bytes_uncompressed = point. to_bytes ( false ) ;
112
112
assert ! ( bytes_compressed. len( ) <= bytes_uncompressed. len( ) ) ;
113
+ assert_eq ! ( bytes_compressed. len( ) , Point :: <E >:: serialized_len( true ) ) ;
114
+ assert_eq ! ( bytes_uncompressed. len( ) , Point :: <E >:: serialized_len( false ) ) ;
113
115
114
116
let p1 = Point :: < E > :: from_bytes ( & bytes_compressed) . unwrap ( ) ;
115
117
let p2 = Point :: < E > :: from_bytes ( & bytes_uncompressed) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments