1
- //SPDX-License-Identifier: MIT
2
- pragma solidity ^ 0.8.0 ;
1
+ // SPDX-License-Identifier: MIT OR Apache-2.0
2
+ pragma solidity ^ 0.8.26 ;
3
3
4
4
import {CBORByteUtils as ByteUtils} from "./components/CBORByteUtils.sol " ;
5
5
import {CBORDataStructures as DataStructures} from "./components/CBORDataStructures.sol " ;
6
+ import {InvalidValue} from "./components/CBORErrors.sol " ;
6
7
import {CBORPrimitives as Primitives} from "./components/CBORPrimitives.sol " ;
7
8
import {CBORSpec as Spec} from "./components/CBORSpec.sol " ;
8
9
import {CBORUtilities as Utils} from "./components/CBORUtilities.sol " ;
@@ -29,7 +30,7 @@ library CBORDecoding {
29
30
uint256 cursor = 0 ;
30
31
// Type check
31
32
(Spec.MajorType majorType , uint8 shortCount ) = Utils.parseFieldEncoding (encoding[cursor]);
32
- require (majorType == Spec.MajorType.Map, "Object is not a mapping! " );
33
+ if (majorType != Spec.MajorType.Map) revert InvalidValue ( "Object is not a mapping " );
33
34
34
35
// Decode and return
35
36
decodedData = DataStructures.expandMapping (encoding, cursor, shortCount);
@@ -53,7 +54,7 @@ library CBORDecoding {
53
54
uint256 cursor = 0 ;
54
55
// Type check
55
56
(Spec.MajorType majorType , uint8 shortCount ) = Utils.parseFieldEncoding (encoding[cursor]);
56
- require (majorType == Spec.MajorType.Array, "Object is not an array! " );
57
+ if (majorType != Spec.MajorType.Array) revert InvalidValue ( "Object is not an array " );
57
58
58
59
// Decode and return
59
60
decodedData = DataStructures.expandArray (encoding, cursor, shortCount);
@@ -78,7 +79,9 @@ library CBORDecoding {
78
79
// See what our field looks like
79
80
(Spec.MajorType majorType , uint8 shortCount , uint256 start , uint256 end , /*next*/ ) =
80
81
Utils.parseField (encoding, cursor);
81
- require (majorType != Spec.MajorType.Array && majorType != Spec.MajorType.Map, "Encoding is not a primitive! " );
82
+ if (majorType != Spec.MajorType.Array && majorType != Spec.MajorType.Map) {
83
+ revert InvalidValue ("Encoding is not a primitive " );
84
+ }
82
85
83
86
// Save our data
84
87
decodedData = Utils.extractValue (encoding, majorType, shortCount, start, end);
@@ -110,7 +113,7 @@ library CBORDecoding {
110
113
{
111
114
// Ensure we start with a mapping
112
115
(Spec.MajorType majorType , uint8 shortCount ) = Utils.parseFieldEncoding (encoding[0 ]);
113
- require (majorType == Spec.MajorType.Map, "Object is not a mapping! " );
116
+ if (majorType != Spec.MajorType.Map) revert InvalidValue ( "Object is not a mapping " );
114
117
115
118
// Figure out where cursor should start.
116
119
if (shortCount == 31 ) {
@@ -143,7 +146,7 @@ library CBORDecoding {
143
146
if (keccak256 (currentItem) == searchKeyHash) keyFound = true ;
144
147
}
145
148
// If the key doesn't exist, revert
146
- revert ("Key not found! " );
149
+ revert InvalidValue ("Key not found " );
147
150
}
148
151
149
152
/**
@@ -167,7 +170,7 @@ library CBORDecoding {
167
170
{
168
171
// Ensure we start with a mapping
169
172
(Spec.MajorType majorType , uint8 shortCount ) = Utils.parseFieldEncoding (encoding[0 ]);
170
- require (majorType == Spec.MajorType.Array, "Object is not an array! " );
173
+ if (majorType != Spec.MajorType.Array) revert InvalidValue ( "Object is not an array " );
171
174
172
175
// Figure out where cursor should start.
173
176
if (shortCount == 31 ) {
@@ -194,7 +197,7 @@ library CBORDecoding {
194
197
cursor = next;
195
198
}
196
199
// If the key doesn't exist, revert
197
- revert ("Item not found! " );
200
+ revert InvalidValue ("Item not found " );
198
201
}
199
202
200
203
/**
@@ -210,7 +213,7 @@ library CBORDecoding {
210
213
{
211
214
// Ensure we start with a mapping
212
215
(Spec.MajorType majorType , uint8 shortCount ) = Utils.parseFieldEncoding (encoding[0 ]);
213
- require (majorType == Spec.MajorType.Array, "Object is not an array! " );
216
+ if (majorType != Spec.MajorType.Array) revert InvalidValue ( "Object is not an array " );
214
217
215
218
// Figure out where cursor should start.
216
219
if (shortCount == 31 ) {
@@ -239,6 +242,6 @@ library CBORDecoding {
239
242
cursor = next;
240
243
}
241
244
// If the index doesn't exist in list, revert
242
- revert ("Index provided larger than list! " );
245
+ revert InvalidValue ("Index provided larger than list " );
243
246
}
244
247
}
0 commit comments