TLA Line data Source code
1 : //! Tools for client/server/stored key management.
2 :
3 : /// Faithfully taken from PostgreSQL.
4 : pub const SCRAM_KEY_LEN: usize = 32;
5 :
6 : /// One of the keys derived from the [password](super::password::SaltedPassword).
7 : /// We use the same structure for all keys, i.e.
8 : /// `ClientKey`, `StoredKey`, and `ServerKey`.
9 CBC 32 : #[derive(Default, PartialEq, Eq)]
10 : #[repr(transparent)]
11 : pub struct ScramKey {
12 : bytes: [u8; SCRAM_KEY_LEN],
13 : }
14 :
15 : impl ScramKey {
16 37 : pub fn sha256(&self) -> Self {
17 37 : super::sha256([self.as_ref()]).into()
18 37 : }
19 :
20 49 : pub fn as_bytes(&self) -> [u8; SCRAM_KEY_LEN] {
21 49 : self.bytes
22 49 : }
23 : }
24 :
25 : impl From<[u8; SCRAM_KEY_LEN]> for ScramKey {
26 : #[inline(always)]
27 133 : fn from(bytes: [u8; SCRAM_KEY_LEN]) -> Self {
28 133 : Self { bytes }
29 133 : }
30 : }
31 :
32 : impl AsRef<[u8]> for ScramKey {
33 : #[inline(always)]
34 103 : fn as_ref(&self) -> &[u8] {
35 103 : &self.bytes
36 103 : }
37 : }
|