@@ -24,14 +24,7 @@ pub const Parser = struct {
2424 bytes : []const u8 ,
2525 index : Index = 0 ,
2626
27- pub const Error = Element .Error || error {
28- UnexpectedElement ,
29- InvalidIntegerEncoding ,
30- Overflow ,
31- NonCanonical ,
32- };
33-
34- pub fn expectBool (self : * Parser ) Error ! bool {
27+ pub fn expectBool (self : * Parser ) ! bool {
3528 const ele = try self .expect (.universal , false , .boolean );
3629 if (ele .slice .len () != 1 ) return error .InvalidBool ;
3730
@@ -42,7 +35,7 @@ pub const Parser = struct {
4235 };
4336 }
4437
45- pub fn expectBitstring (self : * Parser ) Error ! BitString {
38+ pub fn expectBitstring (self : * Parser ) ! BitString {
4639 const ele = try self .expect (.universal , false , .bitstring );
4740 const bytes = self .view (ele );
4841 const right_padding = bytes [0 ];
@@ -54,7 +47,7 @@ pub const Parser = struct {
5447 }
5548
5649 // TODO: return high resolution date time type instead of epoch seconds
57- pub fn expectDateTime (self : * Parser ) Error ! i64 {
50+ pub fn expectDateTime (self : * Parser ) ! i64 {
5851 const ele = try self .expect (.universal , false , null );
5952 const bytes = self .view (ele );
6053 switch (ele .identifier .tag ) {
@@ -93,12 +86,12 @@ pub const Parser = struct {
9386 }
9487 }
9588
96- pub fn expectOid (self : * Parser ) Error ! []const u8 {
89+ pub fn expectOid (self : * Parser ) ! []const u8 {
9790 const oid = try self .expect (.universal , false , .object_identifier );
9891 return self .view (oid );
9992 }
10093
101- pub fn expectEnum (self : * Parser , comptime Enum : type ) Error ! Enum {
94+ pub fn expectEnum (self : * Parser , comptime Enum : type ) ! Enum {
10295 const oid = try self .expectOid ();
10396 return Enum .oids .get (oid ) orelse {
10497 if (builtin .mode == .Debug ) {
@@ -111,7 +104,7 @@ pub const Parser = struct {
111104 };
112105 }
113106
114- pub fn expectInt (self : * Parser , comptime T : type ) Error ! T {
107+ pub fn expectInt (self : * Parser , comptime T : type ) ! T {
115108 const ele = try self .expectPrimitive (.integer );
116109 const bytes = self .view (ele );
117110
@@ -130,7 +123,7 @@ pub const Parser = struct {
130123 return @bitCast (result );
131124 }
132125
133- pub fn expectString (self : * Parser , allowed : std .EnumSet (String.Tag )) Error ! String {
126+ pub fn expectString (self : * Parser , allowed : std .EnumSet (String.Tag )) ! String {
134127 const ele = try self .expect (.universal , false , null );
135128 switch (ele .identifier .tag ) {
136129 inline .string_utf8 ,
@@ -154,7 +147,7 @@ pub const Parser = struct {
154147 return error .UnexpectedElement ;
155148 }
156149
157- pub fn expectPrimitive (self : * Parser , tag : ? Identifier.Tag ) Error ! Element {
150+ pub fn expectPrimitive (self : * Parser , tag : ? Identifier.Tag ) ! Element {
158151 var elem = try self .expect (.universal , false , tag );
159152 if (tag == .integer and elem .slice .len () > 0 ) {
160153 if (self .view (elem )[0 ] == 0 ) elem .slice .start += 1 ;
@@ -164,16 +157,16 @@ pub const Parser = struct {
164157 }
165158
166159 /// Remember to call `expectEnd`
167- pub fn expectSequence (self : * Parser ) Error ! Element {
160+ pub fn expectSequence (self : * Parser ) ! Element {
168161 return try self .expect (.universal , true , .sequence );
169162 }
170163
171164 /// Remember to call `expectEnd`
172- pub fn expectSequenceOf (self : * Parser ) Error ! Element {
165+ pub fn expectSequenceOf (self : * Parser ) ! Element {
173166 return try self .expect (.universal , true , .sequence_of );
174167 }
175168
176- pub fn expectEnd (self : * Parser , val : usize ) Error ! void {
169+ pub fn expectEnd (self : * Parser , val : usize ) ! void {
177170 if (self .index != val ) return error .NonCanonical ; // either forgot to parse end OR an attacker
178171 }
179172
@@ -182,7 +175,7 @@ pub const Parser = struct {
182175 class : ? Identifier.Class ,
183176 constructed : ? bool ,
184177 tag : ? Identifier.Tag ,
185- ) Error ! Element {
178+ ) ! Element {
186179 if (self .index >= self .bytes .len ) return error .EndOfStream ;
187180
188181 const res = try Element .init (self .bytes , self .index );
@@ -229,9 +222,7 @@ pub const Element = struct {
229222 }
230223 };
231224
232- pub const Error = error { InvalidLength , EndOfStream };
233-
234- pub fn init (bytes : []const u8 , index : Index ) Error ! Element {
225+ pub fn init (bytes : []const u8 , index : Index ) ! Element {
235226 var stream = std .io .fixedBufferStream (bytes [index .. ]);
236227 var reader = stream .reader ();
237228
0 commit comments