Skip to content

Commit 230dab1

Browse files
authored
RUST-1716 Add BSON Binary Data subtype Sensitive (#454)
- Sync BSON corpus test - Implement and test BinarySubtype::Sensitive which maps to 0x08
1 parent 81a9895 commit 230dab1

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/spec.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const BINARY_SUBTYPE_UUID: u8 = 0x04;
5454
const BINARY_SUBTYPE_MD5: u8 = 0x05;
5555
const BINARY_SUBTYPE_ENCRYPTED: u8 = 0x06;
5656
const BINARY_SUBTYPE_COLUMN: u8 = 0x07;
57+
const BINARY_SUBTYPE_SENSITIVE: u8 = 0x08;
5758
const BINARY_SUBTYPE_USER_DEFINED: u8 = 0x80;
5859

5960
/// All available BSON element types.
@@ -153,6 +154,7 @@ pub enum BinarySubtype {
153154
Md5,
154155
Encrypted,
155156
Column,
157+
Sensitive,
156158
UserDefined(u8),
157159
Reserved(u8),
158160
}
@@ -169,6 +171,7 @@ impl From<BinarySubtype> for u8 {
169171
BinarySubtype::Md5 => BINARY_SUBTYPE_MD5,
170172
BinarySubtype::Encrypted => BINARY_SUBTYPE_ENCRYPTED,
171173
BinarySubtype::Column => BINARY_SUBTYPE_COLUMN,
174+
BinarySubtype::Sensitive => BINARY_SUBTYPE_SENSITIVE,
172175
BinarySubtype::UserDefined(x) => x,
173176
BinarySubtype::Reserved(x) => x,
174177
}
@@ -187,6 +190,7 @@ impl From<u8> for BinarySubtype {
187190
BINARY_SUBTYPE_MD5 => BinarySubtype::Md5,
188191
BINARY_SUBTYPE_ENCRYPTED => BinarySubtype::Encrypted,
189192
BINARY_SUBTYPE_COLUMN => BinarySubtype::Column,
193+
BINARY_SUBTYPE_SENSITIVE => BinarySubtype::Sensitive,
190194
_ if t < BINARY_SUBTYPE_USER_DEFINED => BinarySubtype::Reserved(t),
191195
_ => BinarySubtype::UserDefined(t),
192196
}

src/tests/binary_subtype.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ fn from_u8() {
77
assert_eq!(BinarySubtype::from(0x00), BinarySubtype::Generic);
88
assert_eq!(BinarySubtype::from(0x06), BinarySubtype::Encrypted);
99
assert_eq!(BinarySubtype::from(0x07), BinarySubtype::Column);
10+
assert_eq!(BinarySubtype::from(0x08), BinarySubtype::Sensitive);
1011
assert_eq!(BinarySubtype::from(0x7F), BinarySubtype::Reserved(0x7F));
1112
assert_eq!(BinarySubtype::from(0x80), BinarySubtype::UserDefined(0x80));
1213
assert_eq!(BinarySubtype::from(0xFF), BinarySubtype::UserDefined(0xFF));

src/tests/spec/json/bson-corpus/binary.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
"canonical_bson": "1D000000057800100000000773FFD26444B34C6990E8E7D1DFC035D400",
5656
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"07\"}}}"
5757
},
58+
{
59+
"description": "subtype 0x08",
60+
"canonical_bson": "1D000000057800100000000873FFD26444B34C6990E8E7D1DFC035D400",
61+
"canonical_extjson": "{\"x\" : { \"$binary\" : {\"base64\" : \"c//SZESzTGmQ6OfR38A11A==\", \"subType\" : \"08\"}}}"
62+
},
5863
{
5964
"description": "subtype 0x80",
6065
"canonical_bson": "0F0000000578000200000080FFFF00",

0 commit comments

Comments
 (0)