asn1 time fractional second support#33
Conversation
beec7b6 to
55ba446
Compare
nodh
left a comment
There was a problem hiding this comment.
Looks fine, only some suggestions
|
|
||
| override val format: Format get() = Format.GENERALIZED | ||
|
|
||
| val fractionDigits: String get() = fractionalSeconds |
There was a problem hiding this comment.
Who would use this property instead of accessing fractionalSeconds directly?
There was a problem hiding this comment.
good catch! makes no sense.
| Format.GENERALIZED -> instant.encodeToAsn1GeneralizedTimePrimitive() | ||
| when (this) { | ||
| is Fractional -> { | ||
| val fraction = fractionDigits |
There was a problem hiding this comment.
Why not use fractionalSeconds directly?
There was a problem hiding this comment.
see above. i was sloppy
| decodable = object : Asn1Decodable<Asn1Primitive, Asn1Time> { | ||
| @Throws(Asn1Exception::class) | ||
| override fun doDecode(src: Asn1Primitive): Asn1Time = | ||
| if (src.tag == Asn1Element.Tag.TIME_UTC) fromUtc(src.content) else decodeGeneralizedTimeToAsn1Time(src.content) |
There was a problem hiding this comment.
nitpick: This line is longer than 120 chars, so it might get reformatted in another PR leading to unrelated changes there
| /** Constructs a whole-second [Asn1Time] from an [Instant]. Sub-second precision is dropped (see [SecondsCapped]). */ | ||
| operator fun invoke(instant: Instant, formatOverride: Format? = null): Asn1Time { | ||
| return if (instant.nanosecondsOfSecond == 0) SecondsCapped(instant, formatOverride) | ||
| else if (formatOverride == Format.UTC) throw IllegalArgumentException("Cannot construct fractional UTC time") |
There was a problem hiding this comment.
nitpick: This line is longer than 120 chars, so it might get reformatted in another PR leading to unrelated changes there
|
|
||
| /** RFC 5280 §4.1.2.5 cut-over: times in `[1950,2050)` use UTC TIME, everything else GENERALIZED TIME. */ | ||
| private fun pickFormat(instant: Instant): Asn1Time.Format = | ||
| if (instant !in THRESHOLD_UTC_TIME..<THRESHOLD_GENERALIZED_TIME) Asn1Time.Format.GENERALIZED else Asn1Time.Format.UTC |
There was a problem hiding this comment.
nitpick: This line is longer than 120 chars, so it might get reformatted in another PR leading to unrelated changes there
| /** | ||
| * Returns a [Instant] with the same epoch seconds, but nanosecond precision capped | ||
| */ | ||
| fun Instant.secondsCapped() =Instant.fromEpochSeconds(this.epochSeconds) No newline at end of file |
| } | ||
|
|
||
| /** | ||
| * Orders OIDs by their DER encoding ([bytes]) using unsigned lexicographic byte comparison — i.e. the |
There was a problem hiding this comment.
This has nothing todo with the PR title
| "T${s[8]}${s[9]}" + // hour | ||
| ":${s[10]}${s[11]}" + // minute | ||
| ":${s[12]}${s[13]}" // seconds | ||
| val sep = s.indexOf('.') |
There was a problem hiding this comment.
nitpick: Would rename to sepIndex because it's not the separator . but its index.
|
|
||
| override val format: Format get() = Format.GENERALIZED | ||
|
|
||
| val fractionDigits: String get() = fractionalSeconds |
There was a problem hiding this comment.
good catch! makes no sense.
| Format.GENERALIZED -> instant.encodeToAsn1GeneralizedTimePrimitive() | ||
| when (this) { | ||
| is Fractional -> { | ||
| val fraction = fractionDigits |
There was a problem hiding this comment.
see above. i was sloppy
Co-authored-by: Christian Kollmann <c.kollmann@gmail.com>
d5185a1 to
e2676b2
Compare
No description provided.