-
-
Save knieriem/ff3b484af1417095aae2b0f82e22df3d to your computer and use it in GitHub Desktop.
probably fixes #19890
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/encoding/asn1/marshal.go b/src/encoding/asn1/marshal.go | |
index 3e85651ffd..bea440dcd1 100644 | |
--- a/src/encoding/asn1/marshal.go | |
+++ b/src/encoding/asn1/marshal.go | |
@@ -384,26 +384,7 @@ func appendTimeCommon(dst []byte, t time.Time) []byte { | |
dst = appendTwoDigits(dst, min) | |
dst = appendTwoDigits(dst, sec) | |
- _, offset := t.Zone() | |
- | |
- switch { | |
- case offset/60 == 0: | |
- return append(dst, 'Z') | |
- case offset > 0: | |
- dst = append(dst, '+') | |
- case offset < 0: | |
- dst = append(dst, '-') | |
- } | |
- | |
- offsetMinutes := offset / 60 | |
- if offsetMinutes < 0 { | |
- offsetMinutes = -offsetMinutes | |
- } | |
- | |
- dst = appendTwoDigits(dst, offsetMinutes/60) | |
- dst = appendTwoDigits(dst, offsetMinutes%60) | |
- | |
- return dst | |
+ return append(dst, 'Z') | |
} | |
func stripTagAndLength(in []byte) []byte { | |
@@ -419,7 +400,7 @@ func makeBody(value reflect.Value, params fieldParameters) (e encoder, err error | |
case flagType: | |
return bytesEncoder(nil), nil | |
case timeType: | |
- t := value.Interface().(time.Time) | |
+ t := value.Interface().(time.Time).UTC() | |
if params.timeType == TagGeneralizedTime || outsideUTCRange(t) { | |
return makeGeneralizedTime(t) | |
} | |
@@ -606,7 +587,7 @@ func makeField(v reflect.Value, params fieldParameters) (e encoder, err error) { | |
tag = params.stringType | |
} | |
case TagUTCTime: | |
- if params.timeType == TagGeneralizedTime || outsideUTCRange(v.Interface().(time.Time)) { | |
+ if params.timeType == TagGeneralizedTime || outsideUTCRange(v.Interface().(time.Time).UTC()) { | |
tag = TagGeneralizedTime | |
} | |
} | |
diff --git a/src/encoding/asn1/marshal_test.go b/src/encoding/asn1/marshal_test.go | |
index 4f755a1f39..0405a3d9ee 100644 | |
--- a/src/encoding/asn1/marshal_test.go | |
+++ b/src/encoding/asn1/marshal_test.go | |
@@ -87,6 +87,7 @@ type numericStringTest struct { | |
type testSET []int | |
var PST = time.FixedZone("PST", -8*60*60) | |
+var CET = time.FixedZone("CET", +1*60*60) | |
type marshalTest struct { | |
in interface{} | |
@@ -118,9 +119,12 @@ var marshalTests = []marshalTest{ | |
{flagTest{false}, "3000"}, | |
{time.Unix(0, 0).UTC(), "170d3730303130313030303030305a"}, | |
{time.Unix(1258325776, 0).UTC(), "170d3039313131353232353631365a"}, | |
- {time.Unix(1258325776, 0).In(PST), "17113039313131353134353631362d30383030"}, | |
+ {time.Unix(1258325776, 0).In(PST), "170d3039313131353232353631365a"}, | |
+ {time.Date(1950, 1, 1, 0, 0, 0, 0, CET), "180f31393439313233313233303030305a"}, | |
+ {time.Date(2049, 12, 31, 23, 0, 0, 0, PST), "180f32303530303130313037303030305a"}, | |
{farFuture(), "180f32313030303430353132303130315a"}, | |
{generalizedTimeTest{time.Unix(1258325776, 0).UTC()}, "3011180f32303039313131353232353631365a"}, | |
+ {generalizedTimeTest{time.Unix(1258325776, 1).UTC()}, "3011180f32303039313131353232353631365a"}, | |
{BitString{[]byte{0x80}, 1}, "03020780"}, | |
{BitString{[]byte{0x81, 0xf0}, 12}, "03030481f0"}, | |
{ObjectIdentifier([]int{1, 2, 3, 4}), "06032a0304"}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment