@@ -14,7 +14,7 @@ export type Md5AuthOptions = {
14
14
credentials : {
15
15
username : string ;
16
16
preHashedPassword : string ;
17
- salt : BufferSource ;
17
+ salt : Uint8Array ;
18
18
hashedPassword : string ;
19
19
} ,
20
20
connectionState : ConnectionState ,
@@ -54,7 +54,7 @@ export class Md5AuthFlow extends BaseAuthFlow {
54
54
this . salt = generateMd5Salt ( ) ;
55
55
}
56
56
57
- async * handleClientMessage ( message : BufferSource ) {
57
+ async * handleClientMessage ( message : Uint8Array ) {
58
58
const length = this . reader . int32 ( ) ;
59
59
const hashedPassword = this . reader . cstring ( ) ;
60
60
@@ -112,22 +112,15 @@ export class Md5AuthFlow extends BaseAuthFlow {
112
112
*
113
113
* @see https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-START-UP
114
114
*/
115
- export async function hashPreHashedPassword ( preHashedPassword : string , salt : BufferSource ) {
116
- const hash = await md5 (
117
- concat ( [
118
- new TextEncoder ( ) . encode ( preHashedPassword ) ,
119
- salt instanceof ArrayBuffer
120
- ? new Uint8Array ( salt )
121
- : new Uint8Array ( salt . buffer , salt . byteOffset , salt . byteLength ) ,
122
- ] ) ,
123
- ) ;
115
+ export async function hashPreHashedPassword ( preHashedPassword : string , salt : Uint8Array ) {
116
+ const hash = await md5 ( concat ( [ new TextEncoder ( ) . encode ( preHashedPassword ) , salt ] ) ) ;
124
117
return `md5${ hash } ` ;
125
118
}
126
119
127
120
/**
128
121
* Computes the MD5 hash of the given value.
129
122
*/
130
- export async function md5 ( value : string | BufferSource ) {
123
+ export async function md5 ( value : string | Uint8Array ) {
131
124
const hash = await crypto . subtle . digest (
132
125
'MD5' ,
133
126
typeof value === 'string' ? new TextEncoder ( ) . encode ( value ) : value ,
0 commit comments