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
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "TestsAppDelegate.h"
static OFString *module;
@implementation TestsAppDelegate (OFASN1DERRepresentationTests)
- (void)ASN1DERRepresentationTests
{
void *pool = objc_autoreleasePoolPush();
OFData *data;
module = @"OFASN1BitString";
TEST(@"-[ASN1DERRepresentation]",
(data = [OFData dataWithItems: "\xFF\x00\xF8" count: 3]) &&
[[[OFASN1BitString bitStringWithBitString: data length: 21]
ASN1DERRepresentation] isEqual:
[OFData dataWithItems: "\x03\x04\x03\xFF\x00\xF8" count: 6]] &&
(data = [OFData dataWithItems: "abcdefäöü" count: 12]) &&
[[[OFASN1BitString bitStringWithBitString: data length: 12 * 8]
ASN1DERRepresentation] isEqual:
[OFData dataWithItems: "\x03\x0D\x00" "abcdefäöü" count: 15]] &&
(data = [OFData dataWithItems: "" count: 0]) &&
[[[OFASN1BitString bitStringWithBitString: data length: 0]
ASN1DERRepresentation] isEqual:
[OFData dataWithItems: "\x03\x01\x00" count: 3]])
module = @"OFNumber";
TEST(@"-[ASN1DERRepresentation] for bool",
[[[OFNumber numberWithBool: false] ASN1DERRepresentation]
isEqual: [OFData dataWithItems: "\x01\x01\x00" count: 3]] &&
[[[OFNumber numberWithBool: true] ASN1DERRepresentation]
isEqual: [OFData dataWithItems: "\x01\x01\xFF" count: 3]])
module = @"OFNull";
TEST(@"-[OFASN1DERRepresentation]",
[[[OFNull null] ASN1DERRepresentation] isEqual:
[OFData dataWithItems: "\x05\x00" count: 2]])
objc_autoreleasePoolPop(pool);
}
@end
|
|
>
<
>
>
|
|
<
<
<
|
>
|
|
|
>
|
>
|
|
|
|
>
|
|
|
|
|
<
>
>
>
|
|
>
>
|
|
|
|
<
>
>
|
|
|
<
<
|
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
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "ObjFW.h"
#import "ObjFWTest.h"
@interface OFASN1DERRepresentationTests: OTTestCase
@end
@implementation OFASN1DERRepresentationTests
- (void)testBitString
{
OFData *data;
data = [OFData dataWithItems: "\xFF\x00\xF8" count: 3];
OTAssertEqualObjects([[OFASN1BitString
bitStringWithBitString: data
length: 21] ASN1DERRepresentation],
[OFData dataWithItems: "\x03\x04\x03\xFF\x00\xF8" count: 6]);
data = [OFData dataWithItems: "abcdefäöü" count: 12];
OTAssertEqualObjects([[OFASN1BitString
bitStringWithBitString: data
length: 12 * 8] ASN1DERRepresentation],
[OFData dataWithItems: "\x03\x0D\x00" "abcdefäöü" count: 15]);
OTAssertEqualObjects([[OFASN1BitString
bitStringWithBitString: [OFData data]
length: 0] ASN1DERRepresentation],
[OFData dataWithItems: "\x03\x01\x00" count: 3]);
}
- (void)testInteger
{
OTAssertEqualObjects(
[[OFNumber numberWithBool: false] ASN1DERRepresentation],
[OFData dataWithItems: "\x01\x01\x00" count: 3]);
OTAssertEqualObjects(
[[OFNumber numberWithBool: true] ASN1DERRepresentation],
[OFData dataWithItems: "\x01\x01\xFF" count: 3]);
}
- (void)testNull
{
OTAssertEqualObjects([[OFNull null] ASN1DERRepresentation],
[OFData dataWithItems: "\x05\x00" count: 2]);
}
@end
|