@@ -109,14 +109,14 @@ func (b *DagLeafBuilder) BuildLeaf(additionalData map[string]string) (*DagLeaf,
109
109
MerkleRoot []byte
110
110
CurrentLinkCount int
111
111
ContentHash []byte
112
- AdditionalData map [ string ] string
112
+ AdditionalData [] keyValue
113
113
}{
114
114
ItemName : b .ItemName ,
115
115
Type : b .LeafType ,
116
116
MerkleRoot : merkleRoot ,
117
117
CurrentLinkCount : len (b .Links ),
118
118
ContentHash : nil ,
119
- AdditionalData : additionalData ,
119
+ AdditionalData : sortMapForVerification ( additionalData ) ,
120
120
}
121
121
122
122
if b .Data != nil {
@@ -190,7 +190,7 @@ func (b *DagLeafBuilder) BuildRootLeaf(dag *DagBuilder, additionalData map[strin
190
190
LatestLabel string
191
191
LeafCount int
192
192
ContentHash []byte
193
- AdditionalData map [ string ] string
193
+ AdditionalData [] keyValue
194
194
}{
195
195
ItemName : b .ItemName ,
196
196
Type : b .LeafType ,
@@ -199,7 +199,7 @@ func (b *DagLeafBuilder) BuildRootLeaf(dag *DagBuilder, additionalData map[strin
199
199
LatestLabel : latestLabel ,
200
200
LeafCount : len (dag .Leafs ),
201
201
ContentHash : nil ,
202
- AdditionalData : additionalData ,
202
+ AdditionalData : sortMapForVerification ( additionalData ) ,
203
203
}
204
204
205
205
if b .Data != nil {
@@ -293,14 +293,14 @@ func (leaf *DagLeaf) VerifyLeaf() error {
293
293
MerkleRoot []byte
294
294
CurrentLinkCount int
295
295
ContentHash []byte
296
- AdditionalData map [ string ] string
296
+ AdditionalData [] keyValue
297
297
}{
298
298
ItemName : leaf .ItemName ,
299
299
Type : leaf .Type ,
300
300
MerkleRoot : leaf .ClassicMerkleRoot ,
301
301
CurrentLinkCount : leaf .CurrentLinkCount ,
302
302
ContentHash : leaf .ContentHash ,
303
- AdditionalData : additionalData ,
303
+ AdditionalData : sortMapForVerification ( additionalData ) ,
304
304
}
305
305
306
306
serializedLeafData , err := cbor .Marshal (leafData )
@@ -363,7 +363,7 @@ func (leaf *DagLeaf) VerifyRootLeaf() error {
363
363
LatestLabel string
364
364
LeafCount int
365
365
ContentHash []byte
366
- AdditionalData map [ string ] string
366
+ AdditionalData [] keyValue
367
367
}{
368
368
ItemName : leaf .ItemName ,
369
369
Type : leaf .Type ,
@@ -372,7 +372,7 @@ func (leaf *DagLeaf) VerifyRootLeaf() error {
372
372
LatestLabel : leaf .LatestLabel ,
373
373
LeafCount : leaf .LeafCount ,
374
374
ContentHash : leaf .ContentHash ,
375
- AdditionalData : additionalData ,
375
+ AdditionalData : sortMapForVerification ( additionalData ) ,
376
376
}
377
377
378
378
serializedLeafData , err := cbor .Marshal (leafData )
@@ -572,3 +572,27 @@ func sortMapByKeys(inputMap map[string]string) map[string]string {
572
572
573
573
return sortedMap
574
574
}
575
+
576
+ type keyValue struct {
577
+ Key string
578
+ Value string
579
+ }
580
+
581
+ func sortMapForVerification (inputMap map [string ]string ) []keyValue {
582
+ if inputMap == nil {
583
+ return nil
584
+ }
585
+
586
+ keys := make ([]string , 0 , len (inputMap ))
587
+ for key := range inputMap {
588
+ keys = append (keys , key )
589
+ }
590
+ sort .Strings (keys )
591
+
592
+ sortedPairs := make ([]keyValue , 0 , len (keys ))
593
+ for _ , key := range keys {
594
+ sortedPairs = append (sortedPairs , keyValue {Key : key , Value : inputMap [key ]})
595
+ }
596
+
597
+ return sortedPairs
598
+ }
0 commit comments