Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUST-1716 Add BSON Binary Data subtype Sensitive #454

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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