-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathCOSEKey.swift
58 lines (52 loc) · 1.23 KB
/
COSEKey.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//===----------------------------------------------------------------------===//
//
// This source file is part of the WebAuthn Swift open source project
//
// Copyright (c) 2023 the WebAuthn Swift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of WebAuthn Swift project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import PotentCBOR
enum COSEKey {
// swiftlint:disable identifier_name
case kty
case alg
// EC2, OKP
case crv
case x
// EC2
case y
// RSA
case n
case e
// swiftlint:enable identifier_name
var cbor: CBOR {
var value: Int
switch self {
case .kty:
value = 1
case .alg:
value = 3
case .crv:
value = -1
case .x:
value = -2
case .y:
value = -3
case .n:
value = -1
case .e:
value = -2
}
if value < 0 {
return .negativeInt(UInt64(abs(-1 - value)))
} else {
return .unsignedInt(UInt64(value))
}
}
}