From fc8e77ca65ab7d4dfd6fd58ad67145f253aab829 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Thu, 13 Feb 2014 12:54:04 -0500 Subject: crypto/x509: Add certificate signature request (CSR) support. This change adds support for parsing and serialisation of PKCS #10, certificate signature requests. LGTM=agl R=golang-codereviews, agl CC=agl, golang-codereviews, nick https://golang.org/cl/49830048 --- src/pkg/encoding/asn1/asn1.go | 14 ++++++++++++++ src/pkg/encoding/asn1/asn1_test.go | 4 ++++ 2 files changed, 18 insertions(+) (limited to 'src/pkg/encoding') diff --git a/src/pkg/encoding/asn1/asn1.go b/src/pkg/encoding/asn1/asn1.go index b8a732e024..7a3c3797c8 100644 --- a/src/pkg/encoding/asn1/asn1.go +++ b/src/pkg/encoding/asn1/asn1.go @@ -23,6 +23,7 @@ import ( "fmt" "math/big" "reflect" + "strconv" "time" ) @@ -197,6 +198,19 @@ func (oi ObjectIdentifier) Equal(other ObjectIdentifier) bool { return true } +func (oi ObjectIdentifier) String() string { + var s string + + for i, v := range oi { + if i > 0 { + s += "." + } + s += strconv.Itoa(v) + } + + return s +} + // parseObjectIdentifier parses an OBJECT IDENTIFIER from the given bytes and // returns it. An object identifier is a sequence of variable length integers // that are assigned in a hierarchy. diff --git a/src/pkg/encoding/asn1/asn1_test.go b/src/pkg/encoding/asn1/asn1_test.go index 4f60b6751d..b553f78e0a 100644 --- a/src/pkg/encoding/asn1/asn1_test.go +++ b/src/pkg/encoding/asn1/asn1_test.go @@ -232,6 +232,10 @@ func TestObjectIdentifier(t *testing.T) { } } } + + if s := ObjectIdentifier([]int{1, 2, 3, 4}).String(); s != "1.2.3.4" { + t.Errorf("bad ObjectIdentifier.String(). Got %s, want 1.2.3.4", s) + } } type timeTest struct { -- cgit v1.3