فهرست منبع

Working on marshal

Jonathan Turner 9 سال پیش
والد
کامیت
8fc184a8ab
3فایلهای تغییر یافته به همراه61 افزوده شده و 5 حذف شده
  1. 4 4
      README.md
  2. 36 0
      debug.go
  3. 21 1
      messages/KDCReq_test.go

+ 4 - 4
README.md

@@ -23,8 +23,8 @@ This is work in progress and does not yet work...
 ## Known Issues
 | Issue | Worked around? | References |
 |-------|-------------|------------|
-| Cannot unmarshal into slice of asn1.RawValue | Yes | [https://github.com/golang/go/issues/17321](https://github.com/golang/go/issues/17321) |
-| Cannot marshal into a GeneralString | Yes - using https://github.com/jcmturner/asn1 | [encoding/asn1: cannot marshal into a GeneralString](https://github.com/golang/go/issues/18832) |
-| Cannot marshal into slice of strings and pass stringtype parameter tags to members | Yes - using https://github.com/jcmturner/asn1 |[encoding/asn1: cannot marshal into slice of strings and pass stringtype parameter tags to members](https://github.com/golang/go/issues/18834) |
+| Cannot unmarshal into slice of asn1.RawValue | Yes | https://github.com/golang/go/issues/17321 |
+| Cannot marshal into a GeneralString | Yes - using https://github.com/jcmturner/asn1 | https://github.com/golang/go/issues/18832 |
+| Cannot marshal into slice of strings and pass stringtype parameter tags to members | Yes - using https://github.com/jcmturner/asn1 | https://github.com/golang/go/issues/18834 |
 | Cannot marshal with application tags | Yes | |
-| Marshalling of bit string does not just marshal the bitstring bytes but also the BitLength attribute | | |
+| Built binary and distributed src seem to be different for encoding/asn1 | No | https://github.com/golang/go/issues/18844 |

+ 36 - 0
debug.go

@@ -0,0 +1,36 @@
+package main
+
+import (
+	"encoding/hex"
+	"fmt"
+	"os"
+	"encoding/asn1"
+	cpasn1 "github.com/jcmturner/asn1/identicalsrc"
+
+)
+
+type BitStringStruct struct {
+	Bs asn1.BitString `asn1:"explicit,tag:0"`
+}
+
+func main() {
+	var o BitStringStruct
+	bs, _ := hex.DecodeString("3009a007030500fedcba90")
+	_, e := asn1.Unmarshal(bs, &o)
+	if e != nil {
+		fmt.Fprintf(os.Stderr, "Error: %v\n", e)
+	} else {
+		fmt.Fprintf(os.Stderr, "Bitstring: %+v\n", o)
+	}
+	n, err := asn1.Marshal(o)
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "Error: %v\n", e)
+	}
+	c, err := cpasn1.Marshal(o)
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "Error: %v\n", e)
+	}
+	fmt.Fprintf(os.Stderr, "Input bytes:         %v\nOutput originalasn1: %v\n", bs, n)
+	fmt.Fprintf(os.Stderr, "Output copy of asn1: %v\n", c)
+
+}

+ 21 - 1
messages/KDCReq_test.go

@@ -394,6 +394,10 @@ func TestUnmarshalASReq_raw(t *testing.T) {
 
 //// Marshal Tests ////
 
+type BitStringStruct struct {
+	Bs asn1.BitString `asn1:"explicit,tag:0"`
+}
+
 func TestMarshalKDCReqBody(t *testing.T) {
 	var a KDCReqBody
 	v := "encode_krb5_kdc_req_body"
@@ -419,7 +423,23 @@ func TestMarshalKDCReqBody(t *testing.T) {
 	j, _ := asn1.Marshal(a.KDCOptions.Bytes)
 	fmt.Fprintf(os.Stderr, "ib: %v\n j: %v\n", b[5:13], j)
 	fmt.Fprintf(os.Stderr, "ib: %v\n j: %v\n", hex.EncodeToString(b[5:13]), hex.EncodeToString(j))
-	fmt.Fprintf(os.Stderr, "bs: %+v", a.KDCOptions.Bytes)
+	fmt.Fprintf(os.Stderr, "bs: %+v\n", a.KDCOptions.Bytes)
+
+	var o BitStringStruct
+	b = append([]byte{byte(48), byte(9), byte(160), byte(7)}, b[6:13]...)
+	fmt.Fprintf(os.Stderr, "b: %v\nh:%v\n", b, hex.EncodeToString(b))
+	_, e := asn1.Unmarshal(b, &o)
+	if e != nil {
+		fmt.Fprintf(os.Stderr, "Error: %v\n", e)
+	} else {
+		fmt.Fprintf(os.Stderr, "Bitstring: %+v\n", o)
+	}
+	c, err := asn1.Marshal(o)
+	if e != nil {
+		fmt.Fprintf(os.Stderr, "Error: %v\n", e)
+	} else {
+		fmt.Fprintf(os.Stderr, "Input bytes:  %v\nOutput bytes: %v", b, c)
+	}
 
 }