summaryrefslogtreecommitdiffstats
path: root/openpgp/src/types
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2023-07-03 11:29:30 +0200
committerJustus Winter <justus@sequoia-pgp.org>2023-07-18 16:41:15 +0200
commit122cdd7c624314651a6c953530bd5204e1996ef0 (patch)
tree1af9c2260a151181319e75a9b45854afb204de44 /openpgp/src/types
parent13d56eddcaa3925fb3bfa8ef42264bf906df3677 (diff)
openpgp: Make Bitfield opaque.
Diffstat (limited to 'openpgp/src/types')
-rw-r--r--openpgp/src/types/bitfield.rs7
-rw-r--r--openpgp/src/types/features.rs9
-rw-r--r--openpgp/src/types/key_flags.rs9
-rw-r--r--openpgp/src/types/server_preferences.rs9
4 files changed, 24 insertions, 10 deletions
diff --git a/openpgp/src/types/bitfield.rs b/openpgp/src/types/bitfield.rs
index 9fce02c3..dea6439a 100644
--- a/openpgp/src/types/bitfield.rs
+++ b/openpgp/src/types/bitfield.rs
@@ -1,7 +1,7 @@
/// A bitfield.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub(crate) struct Bitfield {
- pub(crate) raw: Vec<u8>,
+ raw: Vec<u8>,
}
impl From<Vec<u8>> for Bitfield {
@@ -63,6 +63,11 @@ impl Bitfield {
&self.raw
}
+ /// Returns a slice containing the raw values.
+ pub(crate) fn as_slice_mut(&mut self) -> &mut [u8] {
+ &mut self.raw
+ }
+
/// Returns whether the specified flag is set.
pub fn get(&self, bit: usize) -> bool {
let byte = bit / 8;
diff --git a/openpgp/src/types/features.rs b/openpgp/src/types/features.rs
index caac3cd2..c77d9f85 100644
--- a/openpgp/src/types/features.rs
+++ b/openpgp/src/types/features.rs
@@ -369,16 +369,19 @@ mod tests {
quickcheck! {
fn roundtrip(val: Features) -> bool {
- let mut q = Features::new(val.as_slice());
+ let mut q_bytes = val.as_slice().to_vec();
+ let q = Features::new(&q_bytes);
assert_eq!(val, q);
assert!(val.normalized_eq(&q));
// Add some padding to q. Make sure they are still equal.
- q.0.raw.push(0);
+ q_bytes.push(0);
+ let q = Features::new(&q_bytes);
assert!(val != q);
assert!(val.normalized_eq(&q));
- q.0.raw.push(0);
+ q_bytes.push(0);
+ let q = Features::new(&q_bytes);
assert!(val != q);
assert!(val.normalized_eq(&q));
diff --git a/openpgp/src/types/key_flags.rs b/openpgp/src/types/key_flags.rs
index 03ef15a4..c2f3e62a 100644
--- a/openpgp/src/types/key_flags.rs
+++ b/openpgp/src/types/key_flags.rs
@@ -483,16 +483,19 @@ mod tests {
quickcheck! {
fn roundtrip(val: KeyFlags) -> bool {
- let mut q = KeyFlags::new(&val.as_slice());
+ let mut q_bytes = val.as_slice().to_vec();
+ let q = KeyFlags::new(&q_bytes);
assert_eq!(val, q);
assert!(val.normalized_eq(&q));
// Add some padding to q. Make sure they are still equal.
- q.0.raw.push(0);
+ q_bytes.push(0);
+ let q = KeyFlags::new(&q_bytes);
assert!(val != q);
assert!(val.normalized_eq(&q));
- q.0.raw.push(0);
+ q_bytes.push(0);
+ let q = KeyFlags::new(&q_bytes);
assert!(val != q);
assert!(val.normalized_eq(&q));
diff --git a/openpgp/src/types/server_preferences.rs b/openpgp/src/types/server_preferences.rs
index 347e66fe..faa1ae4a 100644
--- a/openpgp/src/types/server_preferences.rs
+++ b/openpgp/src/types/server_preferences.rs
@@ -298,16 +298,19 @@ mod tests {
quickcheck! {
fn roundtrip(val: KeyServerPreferences) -> bool {
- let mut q = KeyServerPreferences::new(val.as_slice());
+ let mut q_bytes = val.as_slice().to_vec();
+ let q = KeyServerPreferences::new(&q_bytes);
assert_eq!(val, q);
assert!(val.normalized_eq(&q));
// Add some padding to q. Make sure they are still equal.
- q.0.raw.push(0);
+ q_bytes.push(0);
+ let q = KeyServerPreferences::new(&q_bytes);
assert!(val != q);
assert!(val.normalized_eq(&q));
- q.0.raw.push(0);
+ q_bytes.push(0);
+ let q = KeyServerPreferences::new(&q_bytes);
assert!(val != q);
assert!(val.normalized_eq(&q));