Skip to content

Commit

Permalink
fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
smrz2001 committed Nov 14, 2021
1 parent 64ff1f7 commit 523609e
Show file tree
Hide file tree
Showing 5 changed files with 9,486 additions and 4,216 deletions.
62 changes: 53 additions & 9 deletions dagjose/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ func main() {
ts := schema.TypeSystem{}
ts.Init()

// Common types
// -- Common types -->

ts.Accumulate(schema.SpawnString("String"))
ts.Accumulate(schema.SpawnBytes("Bytes"))
ts.Accumulate(schema.SpawnInt("Int"))
Expand Down Expand Up @@ -44,28 +45,32 @@ func main() {
))

// While `Base64Url` is a `String` type and generated through the schema, it has some (surgical) modifications that
// allow it to be treated as a base64url "lens" looking at raw, un-encoded bytes.
// allow it to be treated as a "base64url string lens" looking at raw, un-encoded bytes. Similarly, while `Raw` is a
// `Bytes` type, it is a "raw bytes lens" with modifications to interpret base64url encoded strings.
ts.Accumulate(schema.SpawnString("Base64Url"))
ts.Accumulate(schema.SpawnBytes("Raw"))

// -- Decode types -->

// JWS
ts.Accumulate(schema.SpawnStruct("Signature", []schema.StructField{
ts.Accumulate(schema.SpawnStruct("DecodedSignature", []schema.StructField{
schema.SpawnStructField("header", "Any", true, false),
schema.SpawnStructField("protected", "Base64Url", true, false),
schema.SpawnStructField("signature", "Base64Url", false, false),
}, schema.SpawnStructRepresentationMap(nil)))

ts.Accumulate(schema.SpawnList("Signatures", "Signature", false))
ts.Accumulate(schema.SpawnList("DecodedSignatures", "DecodedSignature", false))

// JWE
ts.Accumulate(schema.SpawnStruct("Recipient", []schema.StructField{
ts.Accumulate(schema.SpawnStruct("DecodedRecipient", []schema.StructField{
schema.SpawnStructField("header", "Any", true, false),
schema.SpawnStructField("encrypted_key", "Base64Url", true, false),
}, schema.SpawnStructRepresentationMap(nil)))

ts.Accumulate(schema.SpawnList("Recipients", "Recipient", false))
ts.Accumulate(schema.SpawnList("DecodedRecipients", "DecodedRecipient", false))

// JOSE
ts.Accumulate(schema.SpawnStruct("JOSE", []schema.StructField{
ts.Accumulate(schema.SpawnStruct("DecodedJOSE", []schema.StructField{
schema.SpawnStructField("aad", "Base64Url", true, false),
schema.SpawnStructField("ciphertext", "Base64Url", true, false),
schema.SpawnStructField("iv", "Base64Url", true, false),
Expand All @@ -78,12 +83,51 @@ func main() {

schema.SpawnStructField("payload", "Base64Url", true, false),
schema.SpawnStructField("protected", "Base64Url", true, false),
schema.SpawnStructField("recipients", "Recipients", true, false),
schema.SpawnStructField("signatures", "Signatures", true, false),
schema.SpawnStructField("recipients", "DecodedRecipients", true, false),
schema.SpawnStructField("signatures", "DecodedSignatures", true, false),
schema.SpawnStructField("tag", "Base64Url", true, false),
schema.SpawnStructField("unprotected", "Any", true, false),
}, schema.SpawnStructRepresentationMap(nil)))

// -- Encode types -->

// JWS
ts.Accumulate(schema.SpawnStruct("EncodedSignature", []schema.StructField{
schema.SpawnStructField("header", "Any", true, false),
schema.SpawnStructField("protected", "Raw", true, false),
schema.SpawnStructField("signature", "Raw", false, false),
}, schema.SpawnStructRepresentationMap(nil)))

ts.Accumulate(schema.SpawnList("EncodedSignatures", "EncodedSignature", false))

// JWE
ts.Accumulate(schema.SpawnStruct("EncodedRecipient", []schema.StructField{
schema.SpawnStructField("header", "Any", true, false),
schema.SpawnStructField("encrypted_key", "Raw", true, false),
}, schema.SpawnStructRepresentationMap(nil)))

ts.Accumulate(schema.SpawnList("EncodedRecipients", "EncodedRecipient", false))

// JOSE
ts.Accumulate(schema.SpawnStruct("EncodedJOSE", []schema.StructField{
schema.SpawnStructField("aad", "Raw", true, false),
schema.SpawnStructField("ciphertext", "Raw", true, false),
schema.SpawnStructField("iv", "Raw", true, false),

// `link` is not encoded as part of DAG-JOSE because it is not included in the DAG-JOSE spec but is included
// here in the schema because it is required during encoding/decoding to/from other encodings (e.g. DAG-JSON).
// If `link` is present during encode, it is validated against `payload` and then ignored. If `payload` is
// present during decode, `link` is added with contents matching `payload`.
schema.SpawnStructField("link", "Link", true, false),

schema.SpawnStructField("payload", "Raw", true, false),
schema.SpawnStructField("protected", "Raw", true, false),
schema.SpawnStructField("recipients", "EncodedRecipients", true, false),
schema.SpawnStructField("signatures", "EncodedSignatures", true, false),
schema.SpawnStructField("tag", "Raw", true, false),
schema.SpawnStructField("unprotected", "Any", true, false),
}, schema.SpawnStructRepresentationMap(nil)))

if errs := ts.ValidateGraph(); errs != nil {
for _, err := range errs {
fmt.Printf("- %s\n", err)
Expand Down
Loading

0 comments on commit 523609e

Please sign in to comment.