summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/ld.py12
-rw-r--r--core/signatures.py4
2 files changed, 12 insertions, 4 deletions
diff --git a/core/ld.py b/core/ld.py
index 7863480..346708c 100644
--- a/core/ld.py
+++ b/core/ld.py
@@ -1,6 +1,6 @@
import datetime
import urllib.parse as urllib_parse
-from typing import Dict, List, Union
+from typing import Dict, List, Optional, Union
from pyld import jsonld
from pyld.jsonld import JsonLdError
@@ -414,5 +414,13 @@ def canonicalise(json_data: Dict, include_security: bool = False) -> Dict:
return jsonld.compact(jsonld.expand(json_data), context)
-def format_date(value: datetime.datetime) -> str:
+def format_ld_date(value: datetime.datetime) -> str:
return value.strftime(DATETIME_FORMAT)
+
+
+def parse_ld_date(value: Optional[str]) -> Optional[datetime.datetime]:
+ if value is None:
+ return None
+ return datetime.datetime.strptime(value, DATETIME_FORMAT).replace(
+ tzinfo=datetime.timezone.utc
+ )
diff --git a/core/signatures.py b/core/signatures.py
index 74b5324..0959333 100644
--- a/core/signatures.py
+++ b/core/signatures.py
@@ -11,7 +11,7 @@ from django.utils.http import http_date, parse_http_date
from OpenSSL import crypto
from pyld import jsonld
-from core.ld import format_date
+from core.ld import format_ld_date
class VerificationError(BaseException):
@@ -261,7 +261,7 @@ class LDSignature:
options: Dict[str, str] = {
"@context": "https://w3id.org/identity/v1",
"creator": key_id,
- "created": format_date(timezone.now()),
+ "created": format_ld_date(timezone.now()),
}
# Get the normalised hash of each document
final_hash = cls.normalized_hash(options) + cls.normalized_hash(document)