forked from StCredZero/SCZ-BasicEncodingRules-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicEncodingRules.h
172 lines (147 loc) · 4.89 KB
/
BasicEncodingRules.h
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//
// BasicEncodingRules.h
//
// Created by Peter Suk on 5/16/12.
// Copyright (c) Ooghamist LLC 2012. All rights reserved.
//
// Distributed under the permissive zlib License
// Get the latest version from here:
//
// https://github.com/StCredZero/SCZ-BasicEncodingRules-iOS
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
#import <Foundation/Foundation.h>
// Bits 7 and 8
// 8 7 6 5 4 3 2 1
// ---------------
// X X 0 0 0 0 0 0
#define kBerClassUniversal 0x00
#define kBerClassApplication 0x40
#define kBerClassContextSpecific 0x80
#define kBerClassPrivate 0xC0
// Bit 6 is primitive or constructed
// 8 7 6 5 4 3 2 1
// ---------------
// 0 0 1 0 0 0 0 0
#define kBerTypeConstructed 0x20
// Bits 1 through 5
// 8 7 6 5 4 3 2 1
// ---------------
// 0 0 0 X X X X X
#define BER_EOC 0x00
#define BER_BOOLEAN 0x01
#define BER_INTEGER 0x02
#define BER_BIT_STRING 0x03
#define BER_OCTET_STRING 0x04
#define BER_NULL 0x05
#define BER_OBJECT_IDENTIFIER 0x06
#define BER_OBJECT_DESCRIPTOR 0x07
#define BER_EXTERNAL 0x08
#define BER_REAL 0x09
#define BER_ENUMERATED 0x0A
#define BER_EMBEDDED_PDV 0x0B
#define BER_UTF8STRING 0x0C
#define BER_RELATIVE_OID 0x0D
#define BER_RESERVED0X0E 0x0E
#define BER_RESERVED0X0F 0x0F
#define BER_SEQUENCE 0x10
#define BER_SET 0x11
#define BER_NUMERICSTRING 0x12
#define BER_PRINTABLESTRING 0x13
#define BER_T61STRING 0x14
#define BER_VIDEOTEXSTRING 0x15
#define BER_IA5STRING 0x16
#define BER_UTCTIME 0x17
#define BER_GENERALIZEDTIME 0x18
#define BER_GRAPHICSTRING 0x19
#define BER_VISIBLESTRING 0x1A
#define BER_GENERALSTRING 0x1B
#define BER_UNIVERSALSTRING 0x1C
#define BER_CHARACTER_STRING 0x1D
#define BER_BMPSTRING 0x1E
#define BER_USE_LONG_FORM 0x1F
#define BER_A0 (kBerClassContextSpecific | kBerTypeConstructed)
#define BER_SEQUENCE_CONSTRUCTED (BER_SEQUENCE | kBerTypeConstructed)
#define BER_SET_CONSTRUCTED (BER_SET | kBerTypeConstructed)
@interface BERVisitor : NSObject
- (id)visitBERLeafNode:(id)leaf;
- (id)visitBERInteriorNode:(id)node;
@end
@interface BERPrintVisitor : BERVisitor
{
NSUInteger indentLevel;
BOOL isIndenting;
NSMutableString * string;
}
@property (nonatomic, assign) NSUInteger indentLevel;
@property (nonatomic, assign) BOOL isIndenting;
@property (nonatomic, strong) NSMutableString * string;
@end
@interface NSObject (BasicEncodingRules)
- (NSData*)berData;
- (uint8_t*)berTag;
- (NSData*)berHeader;
- (NSUInteger)berLengthBytes;
- (NSUInteger)berContentsLengthBytes;
- (NSData*)berContents;
- (id)berDecode;
- (id)berParse;
//Utility Methods
- (void)raiseUnimplemented;
- (NSData*)zeroByteData;
- (NSString*)berTagDescription;
- (NSString*)berContentsDescription;
- (void)acceptBERVisitor:(BERVisitor*)visitor;
@end
@interface NSString (BasicEncodingRules)
- (NSData*)berDataUsingEncoding:(NSStringEncoding)encoding;
- (NSUInteger)berContentsLengthBytesUsingEncoding:(NSStringEncoding)encoding;
@end
@interface NSData (BasicEncodingRules)
@end
@interface NSArray (BasicEncodingRules)
@end
@interface NSNull (BasicEncodingRules)
@end
@interface BerTaggedObject : NSObject {
uint8_t berTag[1];
id obj;
NSUInteger start;
NSUInteger end;
}
@property (nonatomic, assign) uint8_t berTagValue;
@property (nonatomic, strong) id obj;
@property (nonatomic, assign) NSUInteger start;
@property (nonatomic, assign) NSUInteger end;
- (void)beMutable;
- (id)unwrapped;
- (NSString*)descriptionFormat;
@end
@interface BerTaggedCollection : BerTaggedObject {}
@property (nonatomic, strong) NSMutableArray *collection;
- (void)addObject:(id)anObject;
-(id)objectAtIndex:(NSUInteger)index;
@end
@interface BerTaggedData : BerTaggedObject {}
@property (nonatomic, strong) NSData *data;
@end
@interface BerTaggedString : BerTaggedObject {}
@property (nonatomic, strong) NSString *string;
@end