From dba37a8cbed409ea1d65de54409601b5ae41ef71 Mon Sep 17 00:00:00 2001 From: Nico Franzeck Date: Thu, 25 Nov 2021 19:37:31 +0100 Subject: [PATCH 1/4] Use name of simple types in elements - instead of using string as type use the real simple type name --- pkg/xsd/element.go | 2 +- .../valid/xmldsig-core-schema.xsd.out | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/xsd/element.go b/pkg/xsd/element.go index 091db0a..f86c553 100644 --- a/pkg/xsd/element.go +++ b/pkg/xsd/element.go @@ -70,7 +70,7 @@ func (e *Element) GoMemLayout() string { func (e *Element) GoTypeName() string { if e.Type != "" { - return e.typ.GoTypeName() + return e.typ.GoName() } else if e.Ref != "" { return e.refElm.GoTypeName() } else if e.isPlainString() { diff --git a/tests/xsd-examples/valid/xmldsig-core-schema.xsd.out b/tests/xsd-examples/valid/xmldsig-core-schema.xsd.out index 9881e60..84509e1 100644 --- a/tests/xsd-examples/valid/xmldsig-core-schema.xsd.out +++ b/tests/xsd-examples/valid/xmldsig-core-schema.xsd.out @@ -56,7 +56,7 @@ type SignatureMethod struct { Algorithm string `xml:"Algorithm,attr"` - HMACOutputLength string `xml:",any"` + HMACOutputLength *HMACOutputLengthType `xml:",any"` } // Element @@ -73,7 +73,7 @@ type Reference struct { DigestMethod DigestMethodType `xml:"DigestMethod"` - DigestValue string `xml:"DigestValue"` + DigestValue DigestValueType `xml:"DigestValue"` } // Element @@ -234,20 +234,20 @@ type SignatureProperty struct { type DSAKeyValue struct { XMLName xml.Name `xml:"DSAKeyValue"` - G string `xml:"G"` + G *CryptoBinary `xml:"G"` - Y string `xml:"Y"` + Y CryptoBinary `xml:"Y"` - J string `xml:"J"` + J *CryptoBinary `xml:"J"` } // Element type RSAKeyValue struct { XMLName xml.Name `xml:"RSAKeyValue"` - Modulus string `xml:"Modulus"` + Modulus CryptoBinary `xml:"Modulus"` - Exponent string `xml:"Exponent"` + Exponent CryptoBinary `xml:"Exponent"` } // XSD ComplexType declarations @@ -304,7 +304,7 @@ type SignatureMethodType struct { Algorithm string `xml:"Algorithm,attr"` - HMACOutputLength string `xml:",any"` + HMACOutputLength *HMACOutputLengthType `xml:",any"` InnerXml string `xml:",innerxml"` } @@ -322,7 +322,7 @@ type ReferenceType struct { DigestMethod DigestMethodType `xml:"DigestMethod"` - DigestValue string `xml:"DigestValue"` + DigestValue DigestValueType `xml:"DigestValue"` InnerXml string `xml:",innerxml"` } @@ -486,11 +486,11 @@ type SignaturePropertyType struct { type DSAKeyValueType struct { XMLName xml.Name - G string `xml:"G"` + G *CryptoBinary `xml:"G"` - Y string `xml:"Y"` + Y CryptoBinary `xml:"Y"` - J string `xml:"J"` + J *CryptoBinary `xml:"J"` InnerXml string `xml:",innerxml"` } @@ -498,9 +498,9 @@ type DSAKeyValueType struct { type RSAKeyValueType struct { XMLName xml.Name - Modulus string `xml:"Modulus"` + Modulus CryptoBinary `xml:"Modulus"` - Exponent string `xml:"Exponent"` + Exponent CryptoBinary `xml:"Exponent"` InnerXml string `xml:",innerxml"` } From 9d9d8da6d47a70481dd6d0fd150e42b46974c349 Mon Sep 17 00:00:00 2001 From: Nico Franzeck Date: Thu, 25 Nov 2021 19:39:32 +0100 Subject: [PATCH 2/4] Compile Restriction for simple types - compile restrictions within simple types - use real type of simple type instead of string --- pkg/template/types.tmpl | 2 +- pkg/xsd/types.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/template/types.tmpl b/pkg/template/types.tmpl index 76f2d51..86bc122 100644 --- a/pkg/template/types.tmpl +++ b/pkg/template/types.tmpl @@ -52,7 +52,7 @@ import ( // XSD SimpleType declarations {{range .ExportableSimpleTypes }} - type {{ .GoName }} string + type {{ .GoName }} {{ .GoTypeName }} {{ $simpleType := . }} {{ range .Enums }} diff --git a/pkg/xsd/types.go b/pkg/xsd/types.go index e617f22..ca58d2e 100644 --- a/pkg/xsd/types.go +++ b/pkg/xsd/types.go @@ -174,6 +174,10 @@ func (st *SimpleType) compile(sch *Schema, parentElement *Element) { if st.schema == nil { st.schema = sch } + + if st.Restriction != nil { + st.Restriction.compile(sch, parentElement) + } } func (st *SimpleType) Attributes() []Attribute { From 944e39e274d79dda355fe89010c2871e8985a46e Mon Sep 17 00:00:00 2001 From: Nico Franzeck Date: Thu, 25 Nov 2021 19:48:55 +0100 Subject: [PATCH 3/4] Expect int64 instead of string for SimpleType HMACOutputLengthType --- tests/xsd-examples/valid/xmldsig-core-schema.xsd.out | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/xsd-examples/valid/xmldsig-core-schema.xsd.out b/tests/xsd-examples/valid/xmldsig-core-schema.xsd.out index 84509e1..1105c40 100644 --- a/tests/xsd-examples/valid/xmldsig-core-schema.xsd.out +++ b/tests/xsd-examples/valid/xmldsig-core-schema.xsd.out @@ -511,4 +511,4 @@ type CryptoBinary string type DigestValueType string -type HMACOutputLengthType string +type HMACOutputLengthType int64 From a7cf97c98213f602d6173d7e18bb001f98937cd0 Mon Sep 17 00:00:00 2001 From: Nico Franzeck Date: Thu, 25 Nov 2021 20:15:54 +0100 Subject: [PATCH 4/4] update pkged.go --- pkg/template/pkged.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/template/pkged.go b/pkg/template/pkged.go index fc39b48..36a8437 100644 --- a/pkg/template/pkged.go +++ b/pkg/template/pkged.go @@ -9,4 +9,4 @@ import ( "github.com/markbates/pkger/pkging/mem" ) -var _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`1f8b08000000000000ffec595d73e23ad2fe2ba774fbfac41f6088b90b64f89a84338180c1535353b2256c0fb2e4d79209ce54fefb9664630c934972f6e66c6ded05b8bbd5925a4f3fdd32c94f10d32de3a0f713c8cf6d9c811ed02396607d8f5106a9fec4b29dfae2290c30d743a61f38b242063430495296892f5044a00780066630c1a007eaf15b1694038f300bb128e5396395740f4510811ecd09d1c0424082416f0b09c79536c790335afa8ed83026981fbdcb9d6bf516a7b5fc88b9b8f096a68b19f70ce572bf9fa00a3f8c4594fb57014bf490052c4949713ae83d8c29e8892cc7dadfc568c4ee19faf0043d645709436ade0a673c56e737afcc16787979d1c0b63cd6cf37c2ede9e92ed4054e520205d64591627e259294c86932dbf289b08031512bd132690d3f0df0f819839e695b5d0d240c61d06bb73a4afc2e62e56e1996f9a7d1fed3b41f8d6eaf6df7ccce55d7765a2dc374baff67583dc3001a88f97724e1aab2ca0bb5e32dde835ea7d3321c0d4c28033dabd376ecb6066624a63bd033557a30e8b55a96d1d6c03246a0671a86a181d1495c7fff9e4264809ea18139924b1a1a583402ef935d798eb6e174a4ca821d07bd6b0ddc883891812c70007a66c7bc6e776cdbec6860c6a5a5db95e7b8ee765f3470ff8eebf1c82f1a187cdc75fdfd7b4e738e11e87d35344333bea9ec4638fbbb557896eccb92fc3d492ea75595dbb0bc55bb1f267f55e15fc115f85697785946e715cea5f607c229a608d3a0e8fdf14eec078e9a5de16b1dfa55c8e45e75b97f057e2130071ac059c632296c1301b4f7c0293768382530dbf950602e8771260799be655902e56a31d363968b58560f939ba45044ba2c5729000d087c1027c4bf1d7bd657e0e7db5862750c53869261cef56d9589da103ec7a9d2a98031c5994e622e2a033e28292b52c16a4187e58aa512c469a4e2ae74d41c441c9e141c9cabc8b26dd3f9c5a0c754e08c42a263f40433c42fdd0889531107274b94c086564fcf2045157697433cf705c1a78104d92745ce6b6841bba1340fc023689e6996dd39d36dd36ae8175b0ad2c0e9601bceb9a6a7bbf820e9450386621a36441d726a36751f72dc699f59620ab3a26989707335fd872c90869ee2a4a91e12f20eb5fd7cbb8584e911cef0bf41fb18d280119c40aa73910590e377cbe2b783afc470e951273e81297fdb35dd8525dceffae85c20559421d3a12a9966e9ca93c38c1f4b3acd540ca5c20348e951116c87652e22c8a3eaa10759d092dca9e396650c49d8340569de54b789e02c134d13c5426430c04d1be32aab4d53ca0869ea975332bc253810241667661ed390e02d89c3e86c575ef00012a2e3030e30ddbf369453c5edda2e3017849d9d2ea71c6e7184215238a95e16337dcb2fba62392d29bba17ce87e1c9e44c18f7255d5897cd1281f7a921311a75081a60cff9f3381914a15f455b1522cca6f3d12226d88eaeb886e6d3c865fd964ff4c33a67aa7d4f3ac6ee48c2b80aa96fe4a67af505752880f692de8bca0024afcb29c8af23895a407ea7e3c6a359850b04435cc5f462ae07eb1cb772a0d54849215ca5426b9c8621aaaa18206d5e3b47c95dffa5e82fe531697ac3fbfa82ef4b252a4b53c4e4ee340beaad5929e8badd939d7af952a590234b0c714b14c0f198134bc6259a81ff4e30515c1208296f131af9491c26c19f63bdeea218bf2a37ec7a6fd96739eedf1f1b27bc32fdaa1eddb1ebfde736f38bf7362c95b44b9fc24987318fe6eb9b3ca08735579effaa5193b14ef385a7a94c260f786578c28fccd302f78d5295f1b552ce438c833acfb318ab3fcb7689584cd20e5b2c5bfe574e4a85cf0237e54aef7edbff92766d5e464ccbbf0bd90ab1f0dbffdbdf9a2010405043d70575c870f96b3f3167deab9360992a1e1b90fe186ee42389e1bc1f8be73573814aee70cb9937c6339e2ce427bf90c4607fbae153d7bb753ea3ff370fee93a7cdc39cbc9a7d5a7c5ea211fc4d7fbc92773ef8d563c28fa89df9a84b8c5c33b328f820411f4c98e7c77f51c8c863fbc45dfd93ea45d5ccc9f36ee2cdbb8883c2643e12d6e3a5f1637f9dc721e2eec62bb363ecbb9d01a526fd1efe2e26657eb4bb9f632943e83848860e4146870c306f14d3819485f230c9261ee59cbf06e87f60bd77cf25b5323306ce2b973e28d4da7f4ad3e54742783b65c2f6eaee1b9f66ea27c779f0754744f6baeda6acfd130f647aba13f5a09cfb58da090e764e16420b15971cf35894f1f3e4f067d03affb643296fbd863dfa8e30f83d6bc40eecc988cf96715cb309a3d7e2ac7f1c8e477bb52de8c23e1dfb218b778ae305a9bce24b929e7c875c7d3c84f10990cec3e1acf0be84e4d345a3d4f2eceaa72b443fb12e7beb355d8ca98bc7d90ac52cfb267be3537fdd1cad9ae4557faaec6e449ed37eab77df7a923f1ba2391f0cb1c3bdbc541ae21e7a55e42484067ce76310d6b2cad55ee0d1436afc5fb0a7ec71c286e8ca0bbe25ebdd7315e93f8cb43845dc74463d391b8485fbf3525d045f9a3ebec907b20dbb5795c672973d038b7c2f7af782ad7dbf8eee1af8d6b12c981cd0dabb1aa3910d6363119916432b06f7dcb36362ec903734ef0f841f1f188f36ab46aa341ff198da7a99f0475feee4633b6594f779bf53c6ae6ef6ed1277e322fcf3f3614dfe4de8ae321dbdf15fdcdd27890f52c6b93e0e1dc0e46cbd01bad7ef8a361b159cf53dfb29fdfe0e9ad6f994ffe68d52ef3795fc5fb516e963501dd4de8278e3119d893cd7a56e3f6b09e1b414262b49e9313e7fa9bc765393e91e71fd84a9663258eabfc588b12eb53dc4343e2b6a12be314e73fc35fdc12c44fcadcfe1ae7b1c6e78d3afb87793b6ef026fe205f87a52ef30d5d9bd638c5871f70342cbcd1d0d8d4789ce76de1dab9b79e6e7cf7e9b5f9a99fd824a032f7e57c750f58d5fc06af971651bc56b95af4779e3be39bf5344223b2f7e9fd67dc12c5c6b5a927ef8b75a4faf9c69d726f354bfd759f7b2b590fa77e87ca758e18561c349dc97826799a7b4face2f4cd2e38dbbbbc9326aff2729523d7acf7d8584e1eb41e94cf74dc8c6379da736056b9375ee1ede5dee7f5f76571139777ea91abcbfa8e3ae365a357a85f4a19a6e2f436717a6700c7bf77e2fffddbe13ffd9df0e55f000000ffff010000ffffb54d00a6251a0000`))) +var _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`1f8b08000000000000ffec596d6fe23a16fe2b57febadce605521aa4fd50e810c2d0de29b404321a8d9cd824191c3b1b3b2de968fefbca4e0881696977bf5c69b51ad19c73fcd83e7ece8bc3f0132474c33818fc04f27393e46000b4478e73aed12464da979cfdc0a1e0da8e233362a003dc3463b9f802450c060074c01d4c31188066fc8685d5c003cc232c2a79ce582ddd4211c660400b423a602120c160b08184e35a9b63c819adb00e1b2704f33dbadab9516f70d6c80f988b13b4349dccb865a890fbfd04b5fb5122e222b80859aa452c646946cac3416f6142c140e405ee7c881887dd32741ea545ec226548819738e7893aa9716174c1af5fbf3a60531de0e719c7065ab68d3481d38c4081355166985f883423729a0ca67c222c6042d44ab40a4f0bd7013c79c1606058ddab0e4819c260d03375257e1789829bba69fc69187f9ad683610f7add817179d133aef4fe65cfeefe433706ba0e3a20e1df9124a68e1f2fd58e37f8090c8ccb7ebf6f9a86221d8341b76b5c5d75c01d49e8160c8c0e70290303e3ca32baa6ad77c06382c0c0d28d0e70a424dd9923b990de015f20fa1e46ecbb0e065ff58efaf7ad03aea5ab3cc3a1dc73211fc665b77f7569f5ed7e07dc7169e9f5f4ee55afdfedffea80dbb7f1970d7e7fc45f1d30fa0ff1c32417f187e6f46ddde85ec9398b56208684855b0e064adc5621eae972de98c0882b261c4cd573c633986325ded7a264e69b4aa218e71faae5a3443a2decb713f0745a5dff2dcbb90e70be84eae6f0155c806f4d77a82af0b83970a9fd81708629c2342c077fbce3f08ea37643f9daf87b1131b957d329be82a01498830ec079ce72296c52013aef31526dd002a530df0650602e87712e0799b661790ae56a09d3125688449623939b6450c49aac7f29800e1078270e347fdbb7bbaf20283689e46aefa67425c79c6b9b9afec610bd2499d2a98009c5b946122e6a03de29292f33c11a4183d58a95122659acfcae75d41e441c1e141c1eabc8b42cc3fecda02554e09c42a261f40c73c44f6184249948c283254e614b6ba6e790a29abbd3215e0482e0c3408aac8322e7b5b4b0d752da07e031348e34d3ba3cd22dc36ce9275b0ad2e26967e9f6b176f03585213b816ad936d9c9dca32143098d5aa2063935da7a0039beec1d59120af3b26d89717b35ed87ac9e969ee1b4adee52f24ede07c5660309d3629ce3ffa22612484346700aa9c6451e428edfad9937075ff1e114d1623ae3e7a1d936aae87e17a3718154d822a641554fedba96278739dfd77b962b1f2a858790d2bd22d816cb58c490c7f5430bf3b02b13abf15bd6382451db1466455bdda482b35cb44d140b91c310b76d8caba8b64d1923a4ad9f4ec9f186e05090441c9979422382372489e2a35d79c9434888867738c4f4e9b5a182aadc6eec027341d8d1e90acae106c71822c5936a7409d336fca46556d3d2aa55ca871624d141147c2fd7259fcad79aeaa1a5051149061569caf0af82098c54a860a02a996251fdd56221b296a8feecd96d8c7bf76b9b6cae59ce5463957a91375d9e714550ddef5f69fb35eb4a8af02e6b048d975440c95f5e50511da796b4505d9e7bad21130a96aa6efadb484ddc6f76f906d7017542c90a652a925ce4098dd45049c3fa7158be8e6f7369c1e0394faaac3fbec54ef4aa52a4b53a4e21df0a504bd20ab1312e8ff52ba5ca2c011df0842962b91631026974c1f248db69fbdb2b86610c4dfd63a88c91d2e8ead63b68f59045f951dcbe699f0317f913dedf846770f1166dce237ebf04cf80df39b1cc5b44b9fca4987318bdb5dc51654485aabc777159ce76e53b40538b33186ecfa01244e199e19c156f068a97bceea4af8daa2ce5382c72ac05094af2e24d36ab84ce21e5f20a3807dae7b05cf023382ad7fbf6bff1d5b66e77d2bb6df49e73f5178a37bfe7feea0004050403302bafa27bd3defa8b21f53d8b84e958f7bdfb684db7119cccf570727b392b6d0a5773863cb7589bb69899e8493e436767cdbaf18b7f33a5c10b8fe69faea287adfde87e5a7e5a2cef8b5172f5e47e329e7c67c9c37298065d37c25d1ecdc83c0e5344d0272b0ebce54be88c7ff88ba1bdb9cffab89c3fafbdbb7ced21f2908e85bfb8befcb2b82ee6a67d7f62179b95fe59ce85e698fa8b611f97d7db467f946b3f4612334a89081dbb44a36b364aae237724b17a14a6e3c2371fa3d9163d2d3ce339e84ef550b788efcd893f31ec0a5b7fa8e8bba39e5c2f69afe17bd6d655d8ede71115fdc39acb9edad3192781b31c07ce52f89ea587a53c278bdc91e466c97dcf2001bdffec8e863a5e0d893b91fb5893406ffc8fc2eebc44de9dee4ef867e5cb38be7bf8548d63c7e0b36d25af27b1086e5882bbbc501cad0cdb4dafab3972ddc9340e5244dc913544937909bda9819ce58b7b725615a32d7aaa781eda1bc5adf4c97f0ad365e69bd65d60ce8dc059da9b95e84bec72429ed57eceb01778cf9792af19894550c5d8de2c76720d392ff35342427a676f16d3a8e1d25c16fe4871f39abfaff0b78f81ca0d077a4bee377bedfd3548f0b88bb1671b6862d89217890dba53023d543c78f616793bb25919fb751e650c5ae756fcfe954ce57aebc0dbfdb5f60c2273607dcd1aae9a1c881a9b701d92ba23eb26302d7ded912234e6044fee553eee795e3acb1e1a0d5fd0649a0569d8c46fe6dcb1f56aba5dafe6713b7eb3c59004e9bc3aff4457f926f756391eb1a759395c3feaf7b29e656d123c9e5ba1f318f9cef247e08ccbf56a9e05a6f572264f6f02d3780e9c65af8ae76dedef4773b3aa09e8ada320b5757764b9ebd55dc3dbfd6aae872949d06a4e0e39375c3f3c56e3ae3cffc852b21cab785c16fb5a945c1ffc1eeb92b7355dea073fff9efcc55d4182b48aedef7eee6b7cdeaab3bf396f27adbc493e98afe34a97f1869e451b9e92dd0fe88c4bdf19ebeb868fe3b82d3cabf057d375e03dbf363f0b528b8454c6be9aafee01b39edfcaeb4793a8bc56b15a0cb7be77c7d7ab698c1cf214d0dbcfb82bcab567515fde17ab58f5f3b537e5fef22e0b5643ee2f653d1cfa1daad6d97358e7a06137796e287c6357f5adc6e62fd05375a278776f985ddf0d750d0c0f7e7896111ceae887ac3f34aaefaaa3f31cea6ab6aa7c982d5ef3eb78efe33cbfb6ddd1549dc7730c7eb0bb9f4f7b6c95b3aa97fc537d87ca311587b78bc33b04d8ff8728feffaf1b7ff7af1bff060000ffff010000ffff1e03315d6b1a0000`)))