1
//! See [`ExportKey`].
2

            
3
use std::ops::Deref;
4

            
5
use arrayvec::ArrayVec;
6
use serde::{Deserialize, Serialize};
7
use zeroize::Zeroize;
8

            
9
/// Secret key derived from the users password on the client. The server has no
10
/// access to it! Can be used to encrypt data and store it safely at the server.
11
1194
#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Zeroize)]
12
#[zeroize(drop)]
13
pub struct ExportKey(ArrayVec<u8, 64>);
14

            
15
impl ExportKey {
16
	/// Create a [`ExportKey`] from a `[u8; 64]`.
17
453
	pub(crate) const fn new(key: ArrayVec<u8, 64>) -> Self {
18
453
		Self(key)
19
453
	}
20

            
21
	/// Returns an [`ArrayVec`] of this key.
22
	#[must_use]
23
440
	pub const fn as_bytes(&self) -> &ArrayVec<u8, 64> {
24
440
		&self.0
25
440
	}
26
}
27

            
28
impl AsRef<ArrayVec<u8, 64>> for ExportKey {
29
146
	fn as_ref(&self) -> &ArrayVec<u8, 64> {
30
146
		self.as_bytes()
31
146
	}
32
}
33

            
34
impl Deref for ExportKey {
35
	type Target = ArrayVec<u8, 64>;
36

            
37
146
	fn deref(&self) -> &Self::Target {
38
146
		self.as_bytes()
39
146
	}
40
}