-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathASN1DERTests.swift
67 lines (49 loc) · 1.6 KB
/
ASN1DERTests.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
//
// ASN1DERTests.swift
// PotentCodables
//
// Copyright © 2021 Outfox, inc.
//
//
// Distributed under the MIT License, See LICENSE for details.
//
import Foundation
@testable import PotentASN1
import XCTest
class ASN1DERTests: XCTestCase {
func testWrite1ByteLengthValue() throws {
let writer = ASN1DERWriter()
try writer.append(tag: 4, length: 0x7f)
XCTAssertEqual(writer.data, Data([0x4, 0x7f]))
}
func testWrite2ByteLengthValue() throws {
let writer = ASN1DERWriter()
try writer.append(tag: 4, length: 0x80)
XCTAssertEqual(writer.data, Data([0x4, 0x81, 0x80]))
}
func testWrite3ByteLengthValueLow() throws {
let writer = ASN1DERWriter()
try writer.append(tag: 4, length: 0x01_00)
XCTAssertEqual(writer.data, Data([0x4, 0x82, 0x01, 0x00]))
}
func testWrite3ByteLengthValueHigh() throws {
let writer = ASN1DERWriter()
try writer.append(tag: 4, length: 0xff_ff)
XCTAssertEqual(writer.data, Data([0x4, 0x82, 0xff, 0xff]))
}
func testWrite4ByteLengthValueLow() throws {
let writer = ASN1DERWriter()
try writer.append(tag: 4, length: 0x01_00_00)
XCTAssertEqual(writer.data, Data([0x4, 0x83, 0x01, 0x00, 0x00]))
}
func testWrite4ByteLengthValueHigh() throws {
let writer = ASN1DERWriter()
try writer.append(tag: 4, length: 0xff_ff_ff)
XCTAssertEqual(writer.data, Data([0x4, 0x83, 0xff, 0xff, 0xff]))
}
func testWrite5ByteLengthValueLow() throws {
let writer = ASN1DERWriter()
try writer.append(tag: 4, length: 0x01_00_00_00)
XCTAssertEqual(writer.data, Data([0x4, 0x84, 0x01, 0x00, 0x00, 0x00]))
}
}