• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LukaJCB / ts-mls / 20445954465

22 Dec 2025 10:44PM UTC coverage: 96.42%. Remained the same
20445954465

push

github

web-flow
Use constant time comparison for MAC verification (#177)

1205 of 1348 branches covered (89.39%)

Branch coverage included in aggregate %.

2 of 3 new or added lines in 2 files covered. (66.67%)

6821 of 6976 relevant lines covered (97.78%)

44637.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

11.43
/src/crypto/implementation/noble/makeHashImpl.ts
1
import { HashAlgorithm, Hash } from "../../hash.js"
2
import { sha256, sha384, sha512 } from "@noble/hashes/sha2.js"
1✔
3
import { hmac } from "@noble/hashes/hmac.js"
1✔
4
import { constantTimeEqual } from "../../../util/constantTimeCompare.js"
1✔
5

6
export function makeHashImpl(h: HashAlgorithm): Hash {
1✔
7
  return {
×
8
    async digest(data) {
×
9
      switch (h) {
×
10
        case "SHA-256":
×
11
          return sha256(data)
×
12
        case "SHA-384":
×
13
          return sha384(data)
×
14
        case "SHA-512":
×
15
          return sha512(data)
×
16
        default:
×
17
          throw new Error(`Unsupported hash algorithm: ${h}`)
×
18
      }
×
19
    },
×
20
    async mac(key, data) {
×
21
      switch (h) {
×
22
        case "SHA-256":
×
23
          return hmac(sha256, key, data)
×
24
        case "SHA-384":
×
25
          return hmac(sha384, key, data)
×
26
        case "SHA-512":
×
27
          return hmac(sha512, key, data)
×
28
        default:
×
29
          throw new Error(`Unsupported hash algorithm: ${h}`)
×
30
      }
×
31
    },
×
32
    async verifyMac(key, mac, data) {
×
33
      const expectedMac = await this.mac(key, data)
×
NEW
34
      return constantTimeEqual(mac, expectedMac)
×
35
    },
×
36
  }
×
37
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc