Skip to content

Commit e90d65e

Browse files
committed
Add coverage and support for Bcrypt v2b
1 parent 7cdd3e2 commit e90d65e

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Lint, Build & Test
1+
name: Lint, Build & Test with Coverage
22
on:
33
push:
44
branches: [ main ]
@@ -18,5 +18,9 @@ jobs:
1818
run: swift build
1919
- name: Test
2020
run: swift test
21+
- name: Generate Coverage Report
22+
uses: vapor/[email protected]
23+
with:
24+
codecov_token: ${{ secrets.CODECOV_TOKEN }}
2125

2226

Sources/Bcrypt/BcryptError.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ public enum BcryptError: Error {
33
case invalidSalt
44
case emptyPassword
55
case invalidCost
6+
case passwordTooLong
67
}

Sources/Bcrypt/EksBlowfish.swift

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -144,28 +144,14 @@
144144

145145
return (a &+ b) ^ c &+ d
146146
}
147-
148-
func BLFRND(s: [[UInt32]], p: [UInt32], i: inout UInt32, j: UInt32, n: Int) {
149-
i ^= F(s: s, x: j) ^ p[n]
147+
148+
var i = 1
149+
while i <= 16 {
150+
Xr ^= F(s: s, x: Xl) ^ p[i]
151+
Xl ^= F(s: s, x: Xr) ^ p[i + 1]
152+
i &+= 2
150153
}
151154

152-
BLFRND(s: s, p: p, i: &Xr, j: Xl, n: 1)
153-
BLFRND(s: s, p: p, i: &Xl, j: Xr, n: 2)
154-
BLFRND(s: s, p: p, i: &Xr, j: Xl, n: 3)
155-
BLFRND(s: s, p: p, i: &Xl, j: Xr, n: 4)
156-
BLFRND(s: s, p: p, i: &Xr, j: Xl, n: 5)
157-
BLFRND(s: s, p: p, i: &Xl, j: Xr, n: 6)
158-
BLFRND(s: s, p: p, i: &Xr, j: Xl, n: 7)
159-
BLFRND(s: s, p: p, i: &Xl, j: Xr, n: 8)
160-
BLFRND(s: s, p: p, i: &Xr, j: Xl, n: 9)
161-
BLFRND(s: s, p: p, i: &Xl, j: Xr, n: 10)
162-
BLFRND(s: s, p: p, i: &Xr, j: Xl, n: 11)
163-
BLFRND(s: s, p: p, i: &Xl, j: Xr, n: 12)
164-
BLFRND(s: s, p: p, i: &Xr, j: Xl, n: 13)
165-
BLFRND(s: s, p: p, i: &Xl, j: Xr, n: 14)
166-
BLFRND(s: s, p: p, i: &Xr, j: Xl, n: 15)
167-
BLFRND(s: s, p: p, i: &Xl, j: Xr, n: 16)
168-
169155
xl = Xr ^ p[17]
170156
xr = Xl
171157
}

Sources/Bcrypt/Hasher.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ extension Bcrypt {
5858
} else {
5959
password + [0]
6060
}
61+
62+
switch version {
63+
case .v2a: break
64+
case .v2b:
65+
guard password.count <= 72 else {
66+
throw BcryptError.passwordTooLong
67+
}
68+
}
6169

6270
if cost < 4 || cost > 31 {
6371
throw BcryptError.invalidCost

0 commit comments

Comments
 (0)