solana_curve25519/
scalar.rs1pub use bytemuck_derive::{Pod, Zeroable};
2
3#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Pod, Zeroable)]
4#[repr(transparent)]
5pub struct PodScalar(pub [u8; 32]);
6
7#[cfg(not(target_os = "solana"))]
8mod target_arch {
9 use {super::*, crate::errors::Curve25519Error, curve25519_dalek::scalar::Scalar};
10
11 impl From<&Scalar> for PodScalar {
12 fn from(scalar: &Scalar) -> Self {
13 Self(scalar.to_bytes())
14 }
15 }
16
17 impl TryFrom<&PodScalar> for Scalar {
18 type Error = Curve25519Error;
19
20 fn try_from(pod: &PodScalar) -> Result<Self, Self::Error> {
21 Scalar::from_canonical_bytes(pod.0)
22 .into_option()
23 .ok_or(Curve25519Error::PodConversion)
24 }
25 }
26
27 impl From<Scalar> for PodScalar {
28 fn from(scalar: Scalar) -> Self {
29 Self(scalar.to_bytes())
30 }
31 }
32
33 impl TryFrom<PodScalar> for Scalar {
34 type Error = Curve25519Error;
35
36 fn try_from(pod: PodScalar) -> Result<Self, Self::Error> {
37 Scalar::from_canonical_bytes(pod.0)
38 .into_option()
39 .ok_or(Curve25519Error::PodConversion)
40 }
41 }
42}