Skip to content

Commit

Permalink
RUST-1716 Add BSON Binary Data subtype Sensitive (#454)
Browse files Browse the repository at this point in the history
- Sync BSON corpus test
- Implement and test BinarySubtype::Sensitive which maps to 0x08
  • Loading branch information
kkloberdanz authored Jan 23, 2024
1 parent 81a9895 commit 230dab1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const BINARY_SUBTYPE_UUID: u8 = 0x04;
const BINARY_SUBTYPE_MD5: u8 = 0x05;
const BINARY_SUBTYPE_ENCRYPTED: u8 = 0x06;
const BINARY_SUBTYPE_COLUMN: u8 = 0x07;
const BINARY_SUBTYPE_SENSITIVE: u8 = 0x08;
const BINARY_SUBTYPE_USER_DEFINED: u8 = 0x80;

/// All available BSON element types.
Expand Down Expand Up @@ -153,6 +154,7 @@ pub enum BinarySubtype {
Md5,
Encrypted,
Column,
Sensitive,
UserDefined(u8),
Reserved(u8),
}
Expand All @@ -169,6 +171,7 @@ impl From<BinarySubtype> for u8 {
BinarySubtype::Md5 => BINARY_SUBTYPE_MD5,
BinarySubtype::Encrypted => BINARY_SUBTYPE_ENCRYPTED,
BinarySubtype::Column => BINARY_SUBTYPE_COLUMN,
BinarySubtype::Sensitive => BINARY_SUBTYPE_SENSITIVE,
BinarySubtype::UserDefined(x) => x,
BinarySubtype::Reserved(x) => x,
}
Expand All @@ -187,6 +190,7 @@ impl From<u8> for BinarySubtype {
BINARY_SUBTYPE_MD5 => BinarySubtype::Md5,
BINARY_SUBTYPE_ENCRYPTED => BinarySubtype::Encrypted,
BINARY_SUBTYPE_COLUMN => BinarySubtype::Column,
BINARY_SUBTYPE_SENSITIVE => BinarySubtype::Sensitive,
_ if t < BINARY_SUBTYPE_USER_DEFINED => BinarySubtype::Reserved(t),
_ => BinarySubtype::UserDefined(t),
}
Expand Down
1 change: 1 addition & 0 deletions src/tests/binary_subtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fn from_u8() {
assert_eq!(BinarySubtype::from(0x00), BinarySubtype::Generic);
assert_eq!(BinarySubtype::from(0x06), BinarySubtype::Encrypted);
assert_eq!(BinarySubtype::from(0x07), BinarySubtype::Column);
assert_eq!(BinarySubtype::from(0x08), BinarySubtype::Sensitive);
assert_eq!(BinarySubtype::from(0x7F), BinarySubtype::Reserved(0x7F));
assert_eq!(BinarySubtype::from(0x80), BinarySubtype::UserDefined(0x80));
assert_eq!(BinarySubtype::from(0xFF), BinarySubtype::UserDefined(0xFF));
Expand Down
5 changes: 5 additions & 0 deletions src/tests/spec/json/bson-corpus/binary.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"canonical_bson": "1D000000057800100000000773FFD26444B34C6990E8E7D1DFC035D400",
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"07\"}}}"
},
{
"description": "subtype 0x08",
"canonical_bson": "1D000000057800100000000873FFD26444B34C6990E8E7D1DFC035D400",
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"08\"}}}"
},
{
"description": "subtype 0x80",
"canonical_bson": "0F0000000578000200000080FFFF00",
Expand Down

0 comments on commit 230dab1

Please sign in to comment.