Skip to content
This repository has been archived by the owner on Mar 13, 2019. It is now read-only.

SEQUENCE or SET of CHOICE types #8

Open
stevenroose opened this issue Jun 19, 2017 · 0 comments
Open

SEQUENCE or SET of CHOICE types #8

stevenroose opened this issue Jun 19, 2017 · 0 comments

Comments

@stevenroose
Copy link

stevenroose commented Jun 19, 2017

Consider this spec:

Fulfillment ::= CHOICE {
  preimageSha256   [0] PreimageFulfillment ,
  prefixSha256     [1] PrefixFulfillment,
  thresholdSha256  [2] ThresholdFulfillment,
  rsaSha256        [3] RsaSha256Fulfillment,
  ed25519Sha256    [4] Ed25519Sha512Fulfillment
}

ThresholdFulfillment ::= SEQUENCE {
  subfulfillments      SET OF Fulfillment,
  subconditions        SET OF Condition
}

So in order to get a SET, we need the set ASN1 tag on the struct field. But we must also indicate what Go types are possible for the Fulfillment interface.

However, with the following code, asn1 tries to match the CHOICE type (some struct that implements the Fulfillment interface) against the SubFulfillments field, which of course does not match the []Fulfillment type.

type FfThresholdSha256 struct {
	SubFulfillments []Fulfillment `asn1:"tag:0,explicit,set,choice:fulfillment"`
	SubConditions   []*Condition  `asn1:"tag:1,explicit,set,choice:condition"`
}

Thus, asn1 should recognize that when a choice it put on a SET or a SEQUENCE, it should match the elements inside the set or the sequence instead of that field itself.

The specific error you get is

invalid Go type '[]cryptoconditions.Fulfillment' for choice 'fulfillment'
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant