-
-
Notifications
You must be signed in to change notification settings - Fork 16
Add the ASN.1 UTC Time type #8
Add the ASN.1 UTC Time type #8
Conversation
public DerAsnUtcTime(DateTime time) | ||
: base(DerAsnTypeTag.UtcTime) | ||
{ | ||
var timeAsString = $"{time.ToString("yyMMddHHmmss")}Z"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use inline formatting here? Something line $"{time:yyMMddHHmmss}Z"
?
_bytes.AddRange(rawData.DequeueAll()); | ||
} | ||
|
||
public DerAsnUtcTime(DateTime time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should take a DateTimeOffset
+ a bool asUtc
+ a bool includeSeconds
, so it supports all flavors as described in https://www.obj-sys.com/asn1tutorial/node15.html
_bytes.AddRange(bytes); | ||
} | ||
|
||
public override object Value => _bytes.ToArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return a parsed DateTimeOffset value, considering all possible flavors. See https://www.obj-sys.com/asn1tutorial/node15.html .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up #19
I addressed the straightforward comments; will give the other comments a go later today or tomorrow. |
src/DerConverter/Asn/DerAsnType.cs
Outdated
@@ -53,6 +53,7 @@ internal static DerAsnType Parse(Queue<byte> data) | |||
case DerAsnTypeTag.Ia5tring: throw new NotImplementedException(); | |||
case DerAsnTypeTag.UnicodeString: throw new NotImplementedException(); | |||
case DerAsnTypeTag.Sequence: return new DerAsnSequence(typeData); | |||
case DerAsnTypeTag.UtcTime: return new DerAsnUtcTime(typeData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While at it, move this line 2 up (between Ia5String and UnicodeString) to keep the same order as in the DerAsnTypeTag
enum. (makes me sleep better 😄 )
{ | ||
string timeAsString = null; | ||
|
||
if (time.Offset == TimeSpan.Zero) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First prepare the timeZonePart
string, after that you only need one if (includeSeconds)
as you can do $"{time:yyMMddHHmmss}{timeZonePart}"
@@ -0,0 +1,91 @@ | |||
using DerConverter.Asn; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename file to DerAsnUtcTimeTests.cs
This adds the
DerAsnUtcTime
class which allows encoding/decoding of UTC Time types.