From eca79464b5ffb72d24c8cb50c82683e5a951f3f3 Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Tue, 9 Jul 2024 21:57:31 -0500 Subject: [PATCH] fix: avoid panic on CBOR decode of CardanoDnsDomain (#69) --- cdns.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/cdns.go b/cdns.go index 2d284d7..86633c1 100644 --- a/cdns.go +++ b/cdns.go @@ -23,6 +23,8 @@ import ( type CardanoDnsTtl uint type CardanoDnsDomain struct { + // This allows the type to be used with cbor.DecodeGeneric + cbor.StructAsArray Origin []byte Records []CardanoDnsDomainRecord AdditionalData CardanoDnsMaybe[any] @@ -53,17 +55,7 @@ func (c *CardanoDnsDomain) UnmarshalCBOR(cborData []byte) error { if tmpData.Constructor() != 1 { return fmt.Errorf("unexpected constructor index: %d", tmpData.Constructor()) } - tmpFields := tmpData.Fields() - c.Origin = tmpFields[0].(cbor.ByteString).Bytes() - for _, record := range tmpFields[1].([]any) { - recordConstr := record.(cbor.Constructor) - var tmpRecord CardanoDnsDomainRecord - if _, err := cbor.Decode(recordConstr.Cbor(), &tmpRecord); err != nil { - return err - } - c.Records = append(c.Records, tmpRecord) - } - return nil + return cbor.DecodeGeneric(tmpData.FieldsCbor(), c) } type CardanoDnsDomainRecord struct {