Skip to content

Commit 17a33ae

Browse files
committed
common: Move the EncryptedData structure from common to the library
Move the EncryptedData from the common.rs file to the Keylime library in the keylime::crypto::encrypted_data module. Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
1 parent cb2cbea commit 17a33ae

File tree

5 files changed

+71
-26
lines changed

5 files changed

+71
-26
lines changed

keylime-agent/src/common.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,6 @@ where
7878
}
7979
}
8080

81-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
82-
pub struct EncryptedData {
83-
bytes: Vec<u8>,
84-
}
85-
86-
impl AsRef<[u8]> for EncryptedData {
87-
fn as_ref(&self) -> &[u8] {
88-
self.bytes.as_slice()
89-
}
90-
}
91-
92-
impl From<&[u8]> for EncryptedData {
93-
fn from(v: &[u8]) -> Self {
94-
EncryptedData { bytes: v.to_vec() }
95-
}
96-
}
97-
98-
impl From<Vec<u8>> for EncryptedData {
99-
fn from(v: Vec<u8>) -> Self {
100-
EncryptedData { bytes: v }
101-
}
102-
}
103-
10481
// TPM data and agent related that can be persisted and loaded on agent startup.
10582
#[derive(Debug, Clone, Serialize, Deserialize)]
10683
pub(crate) struct AgentData {

keylime-agent/src/keys_handler.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Copyright 2021 Keylime Authors
33

44
use crate::{
5-
common::{EncryptedData, JsonWrapper},
5+
common::JsonWrapper,
66
config::KeylimeConfig,
77
payloads::{Payload, PayloadMessage},
88
Error, QuoteData, Result,
@@ -11,8 +11,9 @@ use actix_web::{http, web, HttpRequest, HttpResponse, Responder};
1111
use base64::{engine::general_purpose, Engine as _};
1212
use keylime::crypto::{
1313
self,
14-
symmkey::{KeySet, SymmKey},
1514
auth_tag::AuthTag,
15+
encrypted_data::EncryptedData,
16+
symmkey::{KeySet, SymmKey},
1617
};
1718
use log::*;
1819
use serde::{Deserialize, Serialize};

keylime-agent/src/payloads.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright 2021 Keylime Authors
33

44
use crate::{
5-
common::EncryptedData,
65
config,
76
revocation::{Revocation, RevocationMessage},
87
Error, Result,
@@ -13,6 +12,7 @@ use crate::revocation::ZmqMessage;
1312

1413
use keylime::crypto::{
1514
self,
15+
encrypted_data::EncryptedData,
1616
symmkey::{KeySet, SymmKey},
1717
};
1818
use log::*;

keylime/src/crypto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2021 Keylime Authors
33

44
pub mod auth_tag;
5+
pub mod encrypted_data;
56
pub mod symmkey;
67
pub mod x509;
78

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright 2025 Keylime Authors
3+
4+
use serde::{Deserialize, Serialize};
5+
6+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7+
pub struct EncryptedData {
8+
bytes: Vec<u8>,
9+
}
10+
11+
impl AsRef<[u8]> for EncryptedData {
12+
fn as_ref(&self) -> &[u8] {
13+
self.bytes.as_slice()
14+
}
15+
}
16+
17+
impl From<&[u8]> for EncryptedData {
18+
fn from(v: &[u8]) -> Self {
19+
EncryptedData { bytes: v.to_vec() }
20+
}
21+
}
22+
23+
impl From<Vec<u8>> for EncryptedData {
24+
fn from(v: Vec<u8>) -> Self {
25+
EncryptedData { bytes: v }
26+
}
27+
}
28+
29+
#[cfg(test)]
30+
mod test {
31+
use super::*;
32+
33+
#[test]
34+
fn test_encrypted_data_as_ref() {
35+
let a = EncryptedData {
36+
bytes: vec![0x0A, 16],
37+
};
38+
39+
let r = a.as_ref();
40+
assert_eq!(r, vec![0x0A, 16]);
41+
}
42+
43+
#[test]
44+
fn test_encrypted_data_from_slice() {
45+
let a: [u8; 16] = [0x0B; 16];
46+
let expected = EncryptedData {
47+
bytes: vec![0x0B; 16],
48+
};
49+
50+
let r = EncryptedData::from(a.as_ref());
51+
52+
assert_eq!(r, expected);
53+
}
54+
55+
#[test]
56+
fn test_encrypted_data_from_vec() {
57+
let a: Vec<u8> = vec![0x0C; 16];
58+
let expected = EncryptedData {
59+
bytes: vec![0x0C; 16],
60+
};
61+
62+
let r = EncryptedData::from(a);
63+
64+
assert_eq!(r, expected);
65+
}
66+
}

0 commit comments

Comments
 (0)