age_crypto/types/
encrypted_data.rs1use std::fmt;
2#[derive(Debug, Clone, PartialEq, Eq)]
3pub struct EncryptedData(Vec<u8>);
4impl EncryptedData {
5 #[must_use]
6 pub(crate) fn new(data: Vec<u8>) -> Self {
7 Self(data)
8 }
9 #[must_use]
10 pub fn as_bytes(&self) -> &[u8] {
11 &self.0
12 }
13 #[must_use]
14 pub fn to_vec(&self) -> Vec<u8> {
15 self.0.clone()
16 }
17 #[must_use]
18 pub fn len(&self) -> usize {
19 self.0.len()
20 }
21 #[must_use]
22 pub fn is_empty(&self) -> bool {
23 self.0.is_empty()
24 }
25}
26impl AsRef<[u8]> for EncryptedData {
27 fn as_ref(&self) -> &[u8] {
28 &self.0
29 }
30}
31impl From<Vec<u8>> for EncryptedData {
32 fn from(data: Vec<u8>) -> Self {
33 Self(data)
34 }
35}
36impl From<EncryptedData> for Vec<u8> {
37 fn from(data: EncryptedData) -> Self {
38 data.0
39 }
40}
41impl fmt::Display for EncryptedData {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 write!(f, "[EncryptedData: {} bytes]", self.0.len())
44 }
45}