Skip to content

Commit fdaab3e

Browse files
authored
grpc: Read timestamps from timestamppb fields instead of int64 fields (#7121)
Switch to reading grpc timestamp values from the new timestamppb protofbuf fields, completely ignoring the old int64 fields. Part 3 of 4 for #7060
1 parent 50ec478 commit fdaab3e

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

grpc/pb-marshalling.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func PBToChallenge(in *corepb.Challenge) (challenge core.Challenge, err error) {
116116
return core.Challenge{}, err
117117
}
118118
var validated *time.Time
119-
if in.ValidatedNS != 0 {
120-
val := time.Unix(0, in.ValidatedNS).UTC()
119+
if in.Validated != nil && !in.Validated.AsTime().IsZero() {
120+
val := in.Validated.AsTime()
121121
validated = &val
122122
}
123123
ch := core.Challenge{
@@ -275,8 +275,8 @@ func PbToRegistration(pb *corepb.Registration) (core.Registration, error) {
275275
return core.Registration{}, err
276276
}
277277
var createdAt *time.Time
278-
if pb.CreatedAtNS != 0 {
279-
c := time.Unix(0, pb.CreatedAtNS).UTC()
278+
if pb.CreatedAt != nil && !pb.CreatedAt.AsTime().IsZero() {
279+
c := pb.CreatedAt.AsTime()
280280
createdAt = &c
281281
}
282282
var contacts *[]string
@@ -344,8 +344,8 @@ func PBToAuthz(pb *corepb.Authorization) (core.Authorization, error) {
344344
challs[i] = chall
345345
}
346346
var expires *time.Time
347-
if pb.ExpiresNS != 0 {
348-
c := time.Unix(0, pb.ExpiresNS).UTC()
347+
if pb.Expires != nil && !pb.Expires.AsTime().IsZero() {
348+
c := pb.Expires.AsTime()
349349
expires = &c
350350
}
351351
authz := core.Authorization{
@@ -396,8 +396,8 @@ func PBToCert(pb *corepb.Certificate) core.Certificate {
396396
Serial: pb.Serial,
397397
Digest: pb.Digest,
398398
DER: pb.Der,
399-
Issued: time.Unix(0, pb.IssuedNS),
400-
Expires: time.Unix(0, pb.ExpiresNS),
399+
Issued: pb.Issued.AsTime(),
400+
Expires: pb.Expires.AsTime(),
401401
}
402402
}
403403

@@ -423,11 +423,11 @@ func PBToCertStatus(pb *corepb.CertificateStatus) core.CertificateStatus {
423423
return core.CertificateStatus{
424424
Serial: pb.Serial,
425425
Status: core.OCSPStatus(pb.Status),
426-
OCSPLastUpdated: time.Unix(0, pb.OcspLastUpdatedNS),
427-
RevokedDate: time.Unix(0, pb.RevokedDateNS),
426+
OCSPLastUpdated: pb.OcspLastUpdated.AsTime(),
427+
RevokedDate: pb.RevokedDate.AsTime(),
428428
RevokedReason: revocation.Reason(pb.RevokedReason),
429-
LastExpirationNagSent: time.Unix(0, pb.LastExpirationNagSentNS),
430-
NotAfter: time.Unix(0, pb.NotAfterNS),
429+
LastExpirationNagSent: pb.LastExpirationNagSent.AsTime(),
430+
NotAfter: pb.NotAfter.AsTime(),
431431
IsExpired: pb.IsExpired,
432432
IssuerNameID: pb.IssuerID,
433433
}

grpc/pb-marshalling_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func TestAuthz(t *testing.T) {
267267
}
268268

269269
func TestCert(t *testing.T) {
270-
now := time.Now().Round(0)
270+
now := time.Now().Round(0).UTC()
271271
cert := core.Certificate{
272272
RegistrationID: 1,
273273
Serial: "serial",

0 commit comments

Comments
 (0)