Skip to content

Commit 112ce07

Browse files
committed
Rename ContextID to ContextId
To better align with the Rust coding standard, rename ContextID to ContextId. Signed-off-by: Daiki Ueno <dueno@redhat.com>
1 parent cd735a3 commit 112ce07

4 files changed

Lines changed: 25 additions & 24 deletions

File tree

agent/src/agent.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use anyhow::{Context as _, Result, bail};
55
use core::future::Future;
6-
use crypto_auditing::types::{ContextID, EventGroup};
6+
use crypto_auditing::types::{ContextId, EventGroup};
77
use libbpf_rs::{
88
RingBufferBuilder,
99
skel::{OpenSkel, SkelBuilder},
@@ -46,7 +46,7 @@ fn bump_memlock_rlimit() -> Result<()> {
4646
Ok(())
4747
}
4848

49-
fn encrypt_context(key: impl AsRef<[u8]>, context: &ContextID) -> Result<ContextID> {
49+
fn encrypt_context(key: impl AsRef<[u8]>, context: &ContextId) -> Result<ContextId> {
5050
let cipher = Cipher::aes_128_ecb();
5151
let mut encryptor = Crypter::new(cipher, Mode::Encrypt, key.as_ref(), None).unwrap();
5252
encryptor.pad(false);
@@ -237,7 +237,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
237237
}
238238

239239
// Encrypt context IDs that appear in the event read
240-
if let Err(e) = group.encrypt_context(|context: &mut ContextID| {
240+
if let Err(e) = group.encrypt_context(|context: &mut ContextId| {
241241
*context = encrypt_context(&encryption_key[..], context)?;
242242
Ok(())
243243
}) {
@@ -303,7 +303,7 @@ mod tests {
303303
let mut group =
304304
EventGroup::from_bytes(&buffer).expect("unable to deserialize to EventGroup");
305305
group
306-
.encrypt_context(|context: &mut ContextID| {
306+
.encrypt_context(|context: &mut ContextId| {
307307
*context = encrypt_context(&encryption_key[..], context)?;
308308
Ok(())
309309
})

crypto-auditing/src/types.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::time::{Duration, Instant};
1414

1515
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
1616

17-
pub type ContextID = [u8; 16];
17+
pub type ContextId = [u8; 16];
1818

1919
fn only_values<K, V, S>(source: &BTreeMap<K, V>, serializer: S) -> Result<S::Ok, S::Error>
2020
where
@@ -32,7 +32,8 @@ where
3232
#[derive(Debug, Default, Serialize)]
3333
pub struct Context {
3434
#[serde_as(as = "Hex")]
35-
pub context: ContextID,
35+
#[serde(rename = "context")]
36+
pub id: ContextId,
3637
#[serde_as(as = "Hex")]
3738
pub origin: Vec<u8>,
3839
#[serde_as(as = "serde_with::DurationNanoSeconds<u64>")]
@@ -42,12 +43,12 @@ pub struct Context {
4243
pub events: BTreeMap<String, EventData>,
4344
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
4445
#[serde(serialize_with = "only_values")]
45-
pub spans: BTreeMap<ContextID, Rc<RefCell<Context>>>,
46+
pub spans: BTreeMap<ContextId, Rc<RefCell<Context>>>,
4647
}
4748

4849
#[derive(Debug)]
4950
pub struct ContextTracker {
50-
all_contexts: BTreeMap<ContextID, Rc<RefCell<Context>>>,
51+
all_contexts: BTreeMap<ContextId, Rc<RefCell<Context>>>,
5152
root_contexts: Vec<(Instant, Rc<RefCell<Context>>)>,
5253
}
5354

@@ -67,7 +68,7 @@ impl ContextTracker {
6768
{
6869
true
6970
} else {
70-
self.all_contexts.remove(&context.borrow().context[..]);
71+
self.all_contexts.remove(&context.borrow().id[..]);
7172
removed.push(context.clone());
7273
false
7374
}
@@ -86,7 +87,7 @@ impl ContextTracker {
8687
origin,
8788
} => {
8889
let context = Rc::new(RefCell::new(Context {
89-
context: *group.context(),
90+
id: *group.context(),
9091
origin: origin.to_owned(),
9192
start: group.start(),
9293
end: group.end(),
@@ -110,7 +111,7 @@ impl ContextTracker {
110111
// has no parent and create a new one so we don't loose the information in
111112
// this message.
112113
let context_obj = Rc::new(RefCell::new(Context {
113-
context: *group.context(),
114+
id: *group.context(),
114115
start: group.start(),
115116
end: group.end(),
116117
..Default::default()
@@ -149,7 +150,7 @@ pub enum EventData {
149150
pub enum Event {
150151
NewContext {
151152
#[serde_as(as = "serde_with::Bytes")]
152-
parent: ContextID,
153+
parent: ContextId,
153154
#[serde_as(as = "serde_with::Bytes")]
154155
origin: Vec<u8>,
155156
},
@@ -163,24 +164,24 @@ pub enum Event {
163164
#[derive(Serialize, Deserialize, Clone, Debug)]
164165
pub struct EventGroup {
165166
#[serde_as(as = "serde_with::Bytes")]
166-
context: ContextID,
167+
context: ContextId,
167168
#[serde_as(as = "serde_with::DurationNanoSeconds<u64>")]
168169
start: Duration,
169170
#[serde_as(as = "serde_with::DurationNanoSeconds<u64>")]
170171
end: Duration,
171172
events: Vec<Event>,
172173
}
173174

174-
fn format_context_id(pid_tgid: u64, context: i64) -> ContextID {
175-
let mut result: ContextID = Default::default();
175+
fn format_context_id(pid_tgid: u64, context: i64) -> ContextId {
176+
let mut result: ContextId = Default::default();
176177
result[..8].copy_from_slice(&u64::to_le_bytes(pid_tgid));
177178
result[8..].copy_from_slice(&i64::to_le_bytes(context));
178179
result
179180
}
180181

181182
impl EventGroup {
182183
/// Returns the context ID associated with the event group
183-
pub fn context(&self) -> &ContextID {
184+
pub fn context(&self) -> &ContextId {
184185
&self.context
185186
}
186187

@@ -208,7 +209,7 @@ impl EventGroup {
208209
/// Returns encrypted context ID associated with the event group
209210
pub fn encrypt_context<F>(&mut self, f: F) -> Result<(), Box<dyn std::error::Error>>
210211
where
211-
F: Fn(&mut ContextID) -> Result<(), Box<dyn std::error::Error>>,
212+
F: Fn(&mut ContextId) -> Result<(), Box<dyn std::error::Error>>,
212213
{
213214
f(&mut self.context)?;
214215

dist/audit.cddl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
LogEntry = EventGroup
22

33
EventGroup = {
4-
context: ContextID
4+
context: ContextId
55
origin: BuildID
66
start: time
77
end: time
@@ -10,12 +10,12 @@ EventGroup = {
1010

1111
Event = NewContext / Data
1212

13-
ContextID = bstr .size 16
13+
ContextId = bstr .size 16
1414
BuildID = bstr .size (20..64)
1515

1616
NewContext = {
1717
NewContext: {
18-
parent: ContextID
18+
parent: ContextId
1919
origin: BuildID
2020
}
2121
}

docs/logging-format.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,19 @@ is the formal definition in [CDDL] (Concise Data Definition Language):
334334
LogEntry = EventGroup
335335
336336
EventGroup = {
337-
context: ContextID
337+
context: ContextId
338338
start: time
339339
end: time
340340
events: [+ Event]
341341
}
342342
343343
Event = NewContext / Data
344344
345-
ContextID = bstr .size 16
345+
ContextId = bstr .size 16
346346
347347
NewContext = {
348348
NewContext: {
349-
parent: ContextID
349+
parent: ContextId
350350
}
351351
}
352352
@@ -361,7 +361,7 @@ Data = {
361361
The log consists of a series of `EventGroup` objects, which groups
362362
events in given time window from `start` to `end`. Timestamps are
363363
represented as a monotonic duration from the kernel boot time.
364-
`ContextID` is an encrypted 16-byte context.
364+
`ContextId` is an encrypted 16-byte context.
365365

366366
### Drawbacks and alternatives
367367

0 commit comments

Comments
 (0)