Documentation
¶
Overview ¶
Package ccf implements CCF specification
Index ¶
Constants ¶
const ( // CBOR tag numbers (128-135) for root objects (131-135 are reserved) CBORTagTypeDef = 128 + iota CBORTagTypeDefAndValue CBORTagTypeAndValue // CBOR tag numbers (136-183) for types // inline types (145-159 are reserved) CBORTagTypeRef CBORTagSimpleType CBORTagOptionalType CBORTagVarsizedArrayType CBORTagConstsizedArrayType CBORTagDictType CBORTagReferenceType CBORTagRestrictedType CBORTagCapabilityType // composite types (165-175 are reserved) CBORTagStructType CBORTagResourceType CBORTagEventType CBORTagContractType CBORTagEnumType // interface types (179-183 are reserved) CBORTagStructInterfaceType CBORTagResourceInterfaceType CBORTagContractInterfaceType // CBOR tag numbers (184-231) for type value // non-composite and non-interface type values (194-207 are reserved) CBORTagTypeValueRef CBORTagSimpleTypeValue CBORTagOptionalTypeValue CBORTagVarsizedArrayTypeValue CBORTagConstsizedArrayTypeValue CBORTagDictTypeValue CBORTagReferenceTypeValue CBORTagRestrictedTypeValue CBORTagCapabilityTypeValue CBORTagFunctionTypeValue // composite type values (213-223 are reserved) CBORTagStructTypeValue CBORTagResourceTypeValue CBORTagEventTypeValue CBORTagContractTypeValue CBORTagEnumTypeValue // interface type values (227-231 are reserved) CBORTagStructInterfaceTypeValue CBORTagResourceInterfaceTypeValue CBORTagContractInterfaceTypeValue )
const ( TypeBool = iota TypeString TypeCharacter TypeAddress TypeInt TypeInt8 TypeInt16 TypeInt32 TypeInt64 TypeInt128 TypeInt256 TypeUInt TypeUInt8 TypeUInt16 TypeUInt32 TypeUInt64 TypeUInt128 TypeUInt256 TypeWord8 TypeWord16 TypeWord32 TypeWord64 TypeFix64 TypeUFix64 TypePath TypeCapabilityPath TypeStoragePath TypePublicPath TypePrivatePath TypeAuthAccount TypePublicAccount TypeAuthAccountKeys TypePublicAccountKeys TypeAuthAccountContracts TypePublicAccountContracts TypeDeployedContract TypeAccountKey TypeBlock TypeAny TypeAnyStruct TypeAnyResource TypeMetaType TypeNever TypeNumber TypeSignedNumber TypeInteger TypeSignedInteger TypeFixedPoint TypeSignedFixedPoint TypeBytes TypeVoid TypeFunction TypeWord128 TypeWord256 TypeAnyStructAttachmentType TypeAnyResourceAttachmentType )
Variables ¶
var CBORDecMode = func() cbor.DecMode { decMode, err := cbor.DecOptions{ IndefLength: cbor.IndefLengthForbidden, IntDec: cbor.IntDecConvertNone, MaxArrayElements: 20_000_000, MaxMapPairs: 20_000_000, MaxNestedLevels: math.MaxInt16, }.DecMode() if err != nil { panic(err) } return decMode }()
CBORDecMode
See https://github.com/fxamacker/cbor: "For best performance, reuse EncMode and DecMode after creating them."
Security Considerations in Section 10 of RFC 8949 states:
"Hostile input may be constructed to overrun buffers, to overflow or underflow integer arithmetic, or to cause other decoding disruption. CBOR data items might have lengths or sizes that are intentionally extremely large or too short. Resource exhaustion attacks might attempt to lure a decoder into allocating very big data items (strings, arrays, maps, or even arbitrary precision numbers) or exhaust the stack depth by setting up deeply nested items. Decoders need to have appropriate resource management to mitigate these attacks."
var CBOREncMode = func() cbor.EncMode { options := cbor.CoreDetEncOptions() options.BigIntConvert = cbor.BigIntConvertNone encMode, err := options.EncMode() if err != nil { panic(err) } return encMode }()
CBOREncMode
See https://github.com/fxamacker/cbor: "For best performance, reuse EncMode and DecMode after creating them."
Functions ¶
func Decode ¶
Decode returns a Cadence value decoded from its CCF-encoded representation.
This function returns an error if the bytes represent CCF that is malformed, invalid, or does not comply with requirements in the CCF specification.
func Encode ¶
Encode returns the CCF-encoded representation of the given value.
This function returns an error if the Cadence value cannot be represented in CCF.
func MustEncode ¶
MustEncode returns the CCF-encoded representation of the given value, or panics if the value cannot be represented in CCF.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes CCF-encoded representations of Cadence values. Since CBOR security considerations apply to CCF, the CBOR codec used by CCF Decoder uses limits (e.g. MaxArrayElements, MaxMapPairs, MaxNestedLevels) specified by CBORDecMode.
func NewDecoder ¶
func NewDecoder(gauge common.MemoryGauge, b []byte) *Decoder
NewDecoder initializes a Decoder that will decode CCF-encoded bytes from the given bytes.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder converts Cadence values into CCF-encoded bytes.
func NewEncoder ¶
NewEncoder initializes an Encoder that will write CCF-encoded bytes to the given io.Writer.