Skip to content

Commit 64f9c20

Browse files
committed
update to crypto rc 3
1 parent 387cf9e commit 64f9c20

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

Sources/PostgreSQL/Connection/PostgreSQLConnection.swift

+5-13
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,12 @@ public final class PostgreSQLConnection {
113113
throw PostgreSQLError(identifier: "usernameUTF8", reason: "Could not convert username to UTF-8 encoded Data.", source: .capture())
114114
}
115115

116-
let hasher = MD5()
117116
// pwdhash = md5(password + username).hexdigest()
118-
var passwordUsernameData = passwordData + usernameData
119-
hasher.update(sequence: &passwordUsernameData)
120-
hasher.finalize()
121-
guard let pwdhash = hasher.hash.hexString.data(using: .utf8) else {
122-
throw PostgreSQLError(identifier: "hashUTF8", reason: "Could not convert password hash to UTF-8 encoded Data.", source: .capture())
123-
}
124-
hasher.reset()
125-
// hash = ′ md 5′ + md 5(pwdhash + salt ).hexdigest ()
126-
var saltedData = pwdhash + salt
127-
hasher.update(sequence: &saltedData)
128-
hasher.finalize()
129-
let passwordMessage = PostgreSQLPasswordMessage(password: "md5" + hasher.hash.hexString)
117+
let pwdhash = try MD5.digest(passwordData + usernameData).hexEncodedString()
118+
// hash = "md5" + md 5(pwdhash + salt).hexdigest()
119+
let hash = try "md5" + MD5.digest(Data(pwdhash.utf8) + salt).hexEncodedString()
120+
121+
let passwordMessage = PostgreSQLPasswordMessage(password: hash)
130122
input = [.password(passwordMessage)]
131123
}
132124

0 commit comments

Comments
 (0)