gmcrypto_core/sm2/public_key.rs
1//! SM2 public keys (compressed/uncompressed encoding lands in v0.3).
2
3use crate::sm2::point::ProjectivePoint;
4
5/// SM2 public key: a curve point `P = d·G`.
6#[derive(Clone, Copy, Debug)]
7pub struct Sm2PublicKey {
8 point: ProjectivePoint,
9}
10
11impl Sm2PublicKey {
12 /// Wrap a curve point as a public key. Caller is responsible for
13 /// having checked the point is on-curve and not at infinity. API entry
14 /// points that need stronger failure guarantees perform their own
15 /// boundary checks.
16 #[must_use]
17 pub const fn from_point(point: ProjectivePoint) -> Self {
18 Self { point }
19 }
20
21 /// Underlying point.
22 #[must_use]
23 pub const fn point(&self) -> ProjectivePoint {
24 self.point
25 }
26}
27
28impl From<ProjectivePoint> for Sm2PublicKey {
29 fn from(p: ProjectivePoint) -> Self {
30 Self::from_point(p)
31 }
32}