curv/elliptic/curves/wrappers/
encoded_point.rs1use std::ops::Deref;
2
3use generic_array::GenericArray;
4
5use crate::elliptic::curves::{Curve, ECPoint};
6
7pub struct EncodedPoint<E: Curve>(pub(super) EncodedPointChoice<E>);
9
10pub(super) enum EncodedPointChoice<E: Curve> {
11 Compressed(GenericArray<u8, <E::Point as ECPoint>::CompressedPointLength>),
12 Uncompressed(GenericArray<u8, <E::Point as ECPoint>::UncompressedPointLength>),
13}
14
15impl<E: Curve> Deref for EncodedPoint<E> {
16 type Target = [u8];
17 fn deref(&self) -> &[u8] {
18 self.as_ref()
19 }
20}
21
22impl<E: Curve> AsRef<[u8]> for EncodedPoint<E> {
23 fn as_ref(&self) -> &[u8] {
24 match &self.0 {
25 EncodedPointChoice::Compressed(bytes) => bytes.as_ref(),
26 EncodedPointChoice::Uncompressed(bytes) => bytes.as_ref(),
27 }
28 }
29}