Skip to content

Commit 6b310fe

Browse files
committed
feat: add sasl payload decoding support
1 parent 42fbc0b commit 6b310fe

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/parse.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import zlib from 'zlib';
22
import { promisify, TextDecoder } from 'util';
3-
import { deserialize } from 'bson';
3+
import { type Binary, deserialize } from 'bson';
44

55
class MessageHeader {
66
messageLength: number;
@@ -54,9 +54,24 @@ type OpContents = OpMsg | OpReply | OpUpdate | OpInsert | OpQuery | OpGetMore |
5454

5555
class BSONBuffer {
5656
data: any;
57+
decodedPayload?: any;
5758

5859
constructor(buf: Uint8Array) {
5960
this.data = deserialize(buf);
61+
let payload: undefined | Binary;
62+
if ((this.data.saslStart || this.data.saslContinue || this.data.conversationId) &&
63+
this.data.payload?._bsontype === 'Binary') {
64+
payload = this.data.payload;
65+
}
66+
if (this.data.speculativeAuthenticate?.payload?._bsontype === 'Binary') {
67+
payload = this.data.speculativeAuthenticate.payload;
68+
}
69+
try {
70+
if (payload) {
71+
this.decodedPayload = deserialize(payload.value());
72+
}
73+
} catch (err) {
74+
}
6075
}
6176
}
6277

0 commit comments

Comments
 (0)