Skip to content

Commit 9aec6bc

Browse files
RUST-453 Add binary subtype 6 (#178)
1 parent dbc863c commit 9aec6bc

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/spec.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const BINARY_SUBTYPE_BINARY_OLD: u8 = 0x02;
5252
const BINARY_SUBTYPE_UUID_OLD: u8 = 0x03;
5353
const BINARY_SUBTYPE_UUID: u8 = 0x04;
5454
const BINARY_SUBTYPE_MD5: u8 = 0x05;
55+
const BINARY_SUBTYPE_ENCRYPTED: u8 = 0x06;
5556

5657
/// All available BSON element types.
5758
///
@@ -148,6 +149,7 @@ pub enum BinarySubtype {
148149
UuidOld,
149150
Uuid,
150151
Md5,
152+
Encrypted,
151153
UserDefined(u8),
152154
}
153155

@@ -161,6 +163,7 @@ impl From<BinarySubtype> for u8 {
161163
BinarySubtype::UuidOld => BINARY_SUBTYPE_UUID_OLD,
162164
BinarySubtype::Uuid => BINARY_SUBTYPE_UUID,
163165
BinarySubtype::Md5 => BINARY_SUBTYPE_MD5,
166+
BinarySubtype::Encrypted => BINARY_SUBTYPE_ENCRYPTED,
164167
BinarySubtype::UserDefined(x) => x,
165168
}
166169
}
@@ -176,6 +179,7 @@ impl From<u8> for BinarySubtype {
176179
BINARY_SUBTYPE_UUID_OLD => BinarySubtype::UuidOld,
177180
BINARY_SUBTYPE_UUID => BinarySubtype::Uuid,
178181
BINARY_SUBTYPE_MD5 => BinarySubtype::Md5,
182+
BINARY_SUBTYPE_ENCRYPTED => BinarySubtype::Encrypted,
179183
_ => BinarySubtype::UserDefined(t),
180184
}
181185
}

tests/modules/macros.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn standard_format() {
3030
"i64": -55,
3131
"timestamp": Bson::Timestamp(Timestamp { time: 0, increment: 229_999_444 }),
3232
"binary": Binary { subtype: BinarySubtype::Md5, bytes: "thingies".to_owned().into_bytes() },
33+
"encrypted": Binary { subtype: BinarySubtype::Encrypted, bytes: "secret".to_owned().into_bytes() },
3334
"_id": id,
3435
"date": Bson::DateTime(date),
3536
};
@@ -38,9 +39,10 @@ fn standard_format() {
3839
"{{ float: 2.4, string: \"hello\", array: [\"testing\", 1, true, [1, 2]], doc: {{ fish: \
3940
\"in\", a: \"barrel\", !: 1 }}, bool: true, null: null, regexp: /s[ao]d/i, \
4041
with_wrapped_parens: -20, code: function(x) {{ return x._id; }}, i32: 12, i64: -55, \
41-
timestamp: Timestamp(0, 229999444), binary: BinData(5, 0x{}), _id: ObjectId(\"{}\"), \
42-
date: Date(\"{}\") }}",
42+
timestamp: Timestamp(0, 229999444), binary: BinData(5, 0x{}), encrypted: BinData(6, \
43+
0x{}), _id: ObjectId(\"{}\"), date: Date(\"{}\") }}",
4344
base64::encode("thingies"),
45+
base64::encode("secret"),
4446
hex::encode(id_string),
4547
date
4648
);

0 commit comments

Comments
 (0)