Skip to content

Commit

Permalink
Serialize timestamps to seconds from Unix epoch for keys
Browse files Browse the repository at this point in the history
  • Loading branch information
heaths committed Aug 28, 2019
1 parent 96a1e5e commit 444f949
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 39 deletions.
8 changes: 4 additions & 4 deletions sdk/keyvault/Azure.Security.KeyVault.Keys/src/DeletedKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ internal override void WriteProperties(Utf8JsonWriter json)

if (DeletedDate.HasValue)
{
json.WriteNumber(DeletedDatePropertyNameBytes, DeletedDate.Value.ToUnixTimeMilliseconds());
json.WriteNumber(DeletedDatePropertyNameBytes, DeletedDate.Value.ToUnixTimeSeconds());
}

if (ScheduledPurgeDate.HasValue)
{
json.WriteNumber(ScheduledPurgeDatePropertyNameBytes, ScheduledPurgeDate.Value.ToUnixTimeMilliseconds());
json.WriteNumber(ScheduledPurgeDatePropertyNameBytes, ScheduledPurgeDate.Value.ToUnixTimeSeconds());
}
}

Expand All @@ -69,10 +69,10 @@ internal override void ReadProperties(JsonElement json)
RecoveryId = prop.Value.GetString();
break;
case DeletedDatePropertyName:
DeletedDate = DateTimeOffset.FromUnixTimeMilliseconds(prop.Value.GetInt64());
DeletedDate = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64());
break;
case ScheduledPurgeDatePropertyName:
ScheduledPurgeDate = DateTimeOffset.FromUnixTimeMilliseconds(prop.Value.GetInt64());
ScheduledPurgeDate = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64());
break;
}
}
Expand Down
12 changes: 6 additions & 6 deletions sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ internal void ReadProperties(JsonElement json)
Enabled = prop.Value.GetBoolean();
break;
case NotBeforePropertyName:
NotBefore = DateTimeOffset.FromUnixTimeMilliseconds(prop.Value.GetInt64());
NotBefore = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64());
break;
case ExpiresPropertyName:
Expires = DateTimeOffset.FromUnixTimeMilliseconds(prop.Value.GetInt64());
Expires = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64());
break;
case CreatedPropertyName:
Created = DateTimeOffset.FromUnixTimeMilliseconds(prop.Value.GetInt64());
Created = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64());
break;
case UpdatedPropertyName:
Updated = DateTimeOffset.FromUnixTimeMilliseconds(prop.Value.GetInt64());
Updated = DateTimeOffset.FromUnixTimeSeconds(prop.Value.GetInt64());
break;
case RecoveryLevelPropertyName:
RecoveryLevel = prop.Value.GetString();
Expand All @@ -92,12 +92,12 @@ internal void WriteProperties(Utf8JsonWriter json)

if (NotBefore.HasValue)
{
json.WriteNumber(NotBeforePropertyNameBytes, NotBefore.Value.ToUnixTimeMilliseconds());
json.WriteNumber(NotBeforePropertyNameBytes, NotBefore.Value.ToUnixTimeSeconds());
}

if (Expires.HasValue)
{
json.WriteNumber(ExpiresPropertyNameBytes, Expires.Value.ToUnixTimeMilliseconds());
json.WriteNumber(ExpiresPropertyNameBytes, Expires.Value.ToUnixTimeSeconds());
}

// Created is read-only don't serialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ internal override void WriteProperties(Utf8JsonWriter json)

if (NotBefore.HasValue)
{
json.WriteNumber(NotBeforePropertyNameBytes, NotBefore.Value.ToUnixTimeMilliseconds());
json.WriteNumber(NotBeforePropertyNameBytes, NotBefore.Value.ToUnixTimeSeconds());
}

if (Expires.HasValue)
{
json.WriteNumber(ExpiresPropertyNameBytes, Expires.Value.ToUnixTimeMilliseconds());
json.WriteNumber(ExpiresPropertyNameBytes, Expires.Value.ToUnixTimeSeconds());
}

json.WriteEndObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for
// license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -47,10 +48,15 @@ public async Task CreateKey()
[Test]
public async Task CreateKeyWithOptions()
{
var exp = new DateTimeOffset(new DateTime(637027248120000000, DateTimeKind.Utc));
var nbf = exp.AddDays(-30);

var keyOptions = new KeyCreateOptions()
{
KeyOperations = new List<KeyOperations>() { KeyOperations.Verify },
Enabled = false
Enabled = false,
Expires = exp,
NotBefore = nbf,
};

Key key = await Client.CreateKeyAsync(Recording.GenerateId(), KeyType.EllipticCurve, keyOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"RequestHeaders": {
"Accept": "application\u002fjson",
"Authorization": "Sanitized",
"Content-Length": "64",
"Content-Length": "98",
"Content-Type": "application\u002fjson",
"Request-Id": "|24a06eb4-44aa1cc26dede9d6.",
"User-Agent": [
Expand All @@ -60,7 +60,9 @@
"RequestBody": {
"kty": "EC",
"attributes": {
"enabled": false
"enabled": false,
"nbf": 1564536012,
"exp": 1567128012
},
"key_ops": [
"verify"
Expand All @@ -69,7 +71,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "365",
"Content-Length": "399",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 17:43:23 GMT",
"Expires": "-1",
Expand All @@ -96,6 +98,8 @@
"y": "aJWhiZgaLjtP0J7ZBNEAKv3fShqjUZleGrQbinhGyp0"
},
"attributes": {
"nbf": 1564536012,
"exp": 1567128012,
"enabled": false,
"created": 1565113404,
"updated": 1565113404,
Expand All @@ -122,7 +126,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "365",
"Content-Length": "399",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 17:43:23 GMT",
"Expires": "-1",
Expand Down Expand Up @@ -150,6 +154,8 @@
},
"attributes": {
"enabled": false,
"nbf": 1564536012,
"exp": 1567128012,
"created": 1565113404,
"updated": 1565113404,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand All @@ -175,7 +181,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "500",
"Content-Length": "534",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 17:43:23 GMT",
"Expires": "-1",
Expand Down Expand Up @@ -206,6 +212,8 @@
},
"attributes": {
"enabled": false,
"nbf": 1564536012,
"exp": 1567128012,
"created": 1565113404,
"updated": 1565113404,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"RequestHeaders": {
"Accept": "application\u002fjson",
"Authorization": "Sanitized",
"Content-Length": "64",
"Content-Length": "98",
"Content-Type": "application\u002fjson",
"Request-Id": "|24a06f71-44aa1cc26dede9d6.",
"User-Agent": [
Expand All @@ -60,7 +60,9 @@
"RequestBody": {
"kty": "EC",
"attributes": {
"enabled": false
"enabled": false,
"nbf": 1564536012,
"exp": 1567128012
},
"key_ops": [
"verify"
Expand All @@ -69,7 +71,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "365",
"Content-Length": "399",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 17:48:45 GMT",
"Expires": "-1",
Expand All @@ -96,9 +98,11 @@
"y": "kOuyMhHZPiJzIOcsytFzQVZ8Bn1AdOosowKOsy2PILA"
},
"attributes": {
"nbf": 1564536012,
"exp": 1567128012,
"enabled": false,
"created": 1565113726,
"updated": 1565113726,
"created": 1565113404,
"updated": 1565113404,
"recoveryLevel": "Recoverable\u002bPurgeable"
}
}
Expand All @@ -122,7 +126,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "365",
"Content-Length": "399",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 17:48:45 GMT",
"Expires": "-1",
Expand Down Expand Up @@ -150,8 +154,10 @@
},
"attributes": {
"enabled": false,
"created": 1565113726,
"updated": 1565113726,
"nbf": 1564536012,
"exp": 1567128012,
"created": 1565113404,
"updated": 1565113404,
"recoveryLevel": "Recoverable\u002bPurgeable"
}
}
Expand All @@ -175,7 +181,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "500",
"Content-Length": "534",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 17:48:45 GMT",
"Expires": "-1",
Expand Down Expand Up @@ -206,8 +212,10 @@
},
"attributes": {
"enabled": false,
"created": 1565113726,
"updated": 1565113726,
"nbf": 1564536012,
"exp": 1567128012,
"created": 1565113404,
"updated": 1565113404,
"recoveryLevel": "Recoverable\u002bPurgeable"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "1473",
"Content-Length": "1467",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 17:45:00 GMT",
"Expires": "-1",
Expand Down Expand Up @@ -336,7 +336,7 @@
"kid": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fkeys\u002fCloudECKey-f4230c5f-348f-4f2d-8aa0-80f4d3ac727d",
"attributes": {
"enabled": true,
"exp": 1596705912685,
"exp": 1596705912,
"created": 1565083512,
"updated": 1565083512,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand All @@ -349,7 +349,7 @@
"kid": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fkeys\u002fCloudRsaKey-f989e30d-d2db-4f87-bd23-ba28ca528ae4",
"attributes": {
"enabled": true,
"exp": 1596705913280,
"exp": 1596705913,
"created": 1565083516,
"updated": 1565083516,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "1473",
"Content-Length": "1467",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 17:50:27 GMT",
"Expires": "-1",
Expand Down Expand Up @@ -336,7 +336,7 @@
"kid": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fkeys\u002fCloudECKey-f4230c5f-348f-4f2d-8aa0-80f4d3ac727d",
"attributes": {
"enabled": true,
"exp": 1596705912685,
"exp": 1596705912,
"created": 1565083512,
"updated": 1565083512,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand All @@ -349,7 +349,7 @@
"kid": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fkeys\u002fCloudRsaKey-f989e30d-d2db-4f87-bd23-ba28ca528ae4",
"attributes": {
"enabled": true,
"exp": 1596705913280,
"exp": 1596705913,
"created": 1565083516,
"updated": 1565083516,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ internal override void WriteProperties(Utf8JsonWriter json)

if (DeletedDate.HasValue)
{
json.WriteNumber("deletedDate", DeletedDate.Value.ToUnixTimeMilliseconds());
json.WriteNumber("deletedDate", DeletedDate.Value.ToUnixTimeSeconds());
}

if (ScheduledPurgeDate.HasValue)
{
json.WriteNumber("scheduledPurgeDate", ScheduledPurgeDate.Value.ToUnixTimeMilliseconds());
json.WriteNumber("scheduledPurgeDate", ScheduledPurgeDate.Value.ToUnixTimeSeconds());
}
}

Expand All @@ -63,12 +63,12 @@ internal override void ReadProperties(JsonElement json)

if (json.TryGetProperty("deletedDate", out JsonElement deletedDate))
{
DeletedDate = DateTimeOffset.FromUnixTimeMilliseconds(deletedDate.GetInt64());
DeletedDate = DateTimeOffset.FromUnixTimeSeconds(deletedDate.GetInt64());
}

if (json.TryGetProperty("scheduledPurgeDate", out JsonElement scheduledPurgeDate))
{
ScheduledPurgeDate = DateTimeOffset.FromUnixTimeMilliseconds(scheduledPurgeDate.GetInt64());
ScheduledPurgeDate = DateTimeOffset.FromUnixTimeSeconds(scheduledPurgeDate.GetInt64());
}
}
}
Expand Down

0 comments on commit 444f949

Please sign in to comment.