File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -93,11 +93,19 @@ type Rat struct {
9393}
9494
9595func (r * Rat ) UnmarshalCBOR (cborData []byte ) error {
96- tmpRat := []int64 {}
96+ tmpRat := []uint64 {}
9797 if _ , err := Decode (cborData , & tmpRat ); err != nil {
9898 return err
9999 }
100- r .Rat = big .NewRat (tmpRat [0 ], tmpRat [1 ])
100+ // Convert numerator and denominator to big.Int
101+ // It's necessary to do this to support num/denom larger than int64 (up to uint64)
102+ tmpNum := new (big.Int )
103+ tmpNum .SetUint64 (tmpRat [0 ])
104+ tmpDenom := new (big.Int )
105+ tmpDenom .SetUint64 (tmpRat [1 ])
106+ // Create new big.Rat with num/denom set to big.Int values above
107+ r .Rat = new (big.Rat )
108+ r .Rat .SetFrac (tmpNum , tmpDenom )
101109 return nil
102110}
103111
Original file line number Diff line number Diff line change @@ -54,6 +54,15 @@ var tagsTestDefs = []struct {
5454 },
5555 ),
5656 },
57+ {
58+ cborHex : "d81e821b80000000000000011b8ac7230489e80000" ,
59+ object : cbor.Rat {
60+ Rat : new (big.Rat ).SetFrac (
61+ new (big.Int ).SetUint64 (9223372036854775809 ),
62+ new (big.Int ).SetUint64 (10000000000000000000 ),
63+ ),
64+ },
65+ },
5766}
5867
5968func TestTagsDecode (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments