Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Add the ASN.1 UTC Time type #8

Merged
merged 6 commits into from
Aug 14, 2018
Merged

Add the ASN.1 UTC Time type #8

merged 6 commits into from
Aug 14, 2018

Conversation

qmfrederik
Copy link
Contributor

This adds the DerAsnUtcTime class which allows encoding/decoding of UTC Time types.

public DerAsnUtcTime(DateTime time)
: base(DerAsnTypeTag.UtcTime)
{
var timeAsString = $"{time.ToString("yyMMddHHmmss")}Z";
Copy link
Owner

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)
Copy link
Owner

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();
Copy link
Owner

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 .

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up #19

@qmfrederik
Copy link
Contributor Author

I addressed the straightforward comments; will give the other comments a go later today or tomorrow.

@@ -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);
Copy link
Owner

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)
Copy link
Owner

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;
Copy link
Owner

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

@huysentruitw huysentruitw changed the base branch from master to develop August 14, 2018 21:10
@huysentruitw huysentruitw merged commit 7c90e27 into huysentruitw:develop Aug 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants