Skip to main content

opaque_vx/key_exchange/sigma_i/
shared.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2// Copyright (c) VexaHub and contributors.
3// Copyright (c) Meta Platforms, Inc. and affiliates.
4
5use derive_where::derive_where;
6use digest::{Output, OutputSizeUser};
7use generic_array::{ArrayLength, GenericArray};
8
9use crate::errors::ProtocolError;
10use crate::key_exchange::{Deserialize, Serialize};
11use crate::serialization::SliceExt;
12
13/// Pre-hash of the message to be verified.
14#[derive_where(Clone, Debug, Eq, Hash, PartialEq, Zeroize)]
15#[cfg_attr(
16    feature = "serde",
17    derive(serde::Deserialize, serde::Serialize),
18    serde(bound = "")
19)]
20#[allow(dead_code)]
21pub struct PreHash<H: OutputSizeUser>(pub Output<H>);
22
23impl<H: OutputSizeUser> Deserialize for PreHash<H>
24where
25    H::OutputSize: ArrayLength,
26{
27    fn deserialize_take(input: &mut &[u8]) -> Result<Self, ProtocolError> {
28        Ok(Self(input.take_array("pre-hash")?.into_ha0_4()))
29    }
30}
31
32impl<H: OutputSizeUser> Serialize for PreHash<H>
33where
34    H::OutputSize: ArrayLength,
35{
36    type Len = H::OutputSize;
37
38    fn serialize(&self) -> GenericArray<u8, Self::Len> {
39        GenericArray::from_slice(self.0.as_slice()).clone()
40    }
41}