-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathTestAttestationObject.swift
130 lines (108 loc) · 3.25 KB
/
TestAttestationObject.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//===----------------------------------------------------------------------===//
//
// 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 Foundation
import WebAuthn
import PotentCBOR
struct TestAttestationObject {
var fmt: CBOR?
var attStmt: CBOR?
var authData: CBOR?
var cborEncoded: [UInt8] {
var attestationObject = CBOR.Map()
if let fmt {
attestationObject[.utf8String("fmt")] = fmt
}
if let attStmt {
attestationObject[.utf8String("attStmt")] = attStmt
}
if let authData {
attestationObject[.utf8String("authData")] = authData
}
let bytes = try! CBORSerialization.data(from: CBOR.map(attestationObject))
return [UInt8](bytes)
}
}
struct TestAttestationObjectBuilder {
private var wrapped: TestAttestationObject
init(wrapped: TestAttestationObject = TestAttestationObject()) {
self.wrapped = wrapped
}
func validMock() -> Self {
var temp = self
temp.wrapped.fmt = .utf8String("none")
temp.wrapped.attStmt = .map([:])
temp.wrapped.authData = .byteString(Data(TestAuthDataBuilder().validMock().build().byteArrayRepresentation))
return temp
}
func build() -> TestAttestationObject {
return wrapped
}
func buildBase64URLEncoded() -> URLEncodedBase64 {
build().cborEncoded.base64URLEncodedString()
}
// MARK: fmt
func invalidFmt() -> Self {
var temp = self
temp.wrapped.fmt = .double(1)
return temp
}
func fmt(_ utf8String: String) -> Self {
var temp = self
temp.wrapped.fmt = .utf8String(utf8String)
return temp
}
// MARK: attStmt
func invalidAttStmt() -> Self {
var temp = self
temp.wrapped.attStmt = .double(1)
return temp
}
func attStmt(_ cbor: CBOR) -> Self {
var temp = self
temp.wrapped.attStmt = cbor
return temp
}
func emptyAttStmt() -> Self {
var temp = self
temp.wrapped.attStmt = .map([:])
return temp
}
func missingAttStmt() -> Self {
var temp = self
temp.wrapped.attStmt = nil
return temp
}
// MARK: authData
func invalidAuthData() -> Self {
var temp = self
temp.wrapped.authData = .double(1)
return temp
}
func emptyAuthData() -> Self {
var temp = self
temp.wrapped.authData = .byteString(Data())
return temp
}
func zeroAuthData(byteCount: Int) -> Self {
var temp = self
temp.wrapped.authData = .byteString(Data(repeating: 0, count: byteCount))
return temp
}
func authData(_ builder: TestAuthDataBuilder) -> Self {
var temp = self
temp.wrapped.authData = .byteString(Data(builder.build().byteArrayRepresentation))
return temp
}
// func authData(_ builder: )
}