if (v > ((uint64_t)1 << (uint8_t)63)) {
return YACErrTAI64TooBig;
}
- switch (l) {
- case 12:
+ if (l > 8) {
v = yacFromBE(buf + 1 + 8, 4);
+ if ((l == 8) && (v == 0)) {
+ return YACErrTAI64NonMinimal;
+ }
if (v > 999999999) {
return YACErrTAI64BadNsec;
}
- break;
- case 16:
+ }
+ if (l > 12) {
v = yacFromBE(buf + 1 + 8 + 4, 4);
+ if (v == 0) {
+ return YACErrTAI64NonMinimal;
+ }
if (v > 999999999) {
return YACErrTAI64BadAsec;
}
- break;
- default:
- break;
}
break;
}
return "TAI64InPast";
case YACErrTAI64IsLeap:
return "TAI64IsLeap";
+ case YACErrTAI64NonMinimal:
+ return "TAI64NonMinimal";
case YACErrMapBadKey:
return "MapBadKey";
case YACErrMapNoVal:
YACErrTAI64BadAsec,
YACErrTAI64InPast,
YACErrTAI64IsLeap,
+ YACErrTAI64NonMinimal,
YACErrMapBadKey,
YACErrMapNoVal,
YACErrMapUnordered,
err = errors.New("reserved TAI64 values in use")
return
}
- switch l {
- case 12:
- if FromBE(buf[1+8:1+8+4]) > 999999999 {
+ if l > 8 {
+ nsecs := FromBE(buf[1+8 : 1+8+4])
+ if l == 8 && nsecs == 0 {
+ err = errors.New("non-minimal TAI64N")
+ return
+ }
+ if nsecs > 999999999 {
err = errors.New("too many nanoseconds")
return
}
- case 16:
- if FromBE(buf[1+8+4:1+8+4+4]) > 999999999 {
+ }
+ if l > 12 {
+ asecs := FromBE(buf[1+8+4 : 1+8+4+4])
+ if asecs == 0 {
+ err = errors.New("non-minimal TAI64NA")
+ return
+ }
+ if asecs > 999999999 {
err = errors.New("too many attoseconds")
return
}
if l > 8:
nsecs = int.from_bytes(v[1+8:1+8+4], "big")
if (l == 8) and (nsecs == 0):
- raise DecodeError("non-minimal encoding")
+ raise DecodeError("non-minimal TAI64N")
if nsecs > 999999999:
raise DecodeError("too many nanoseconds")
asecs = 0
if l > 12:
asecs = int.from_bytes(v[1+8+4:1+8+4+4], "big")
if asecs == 0:
- raise DecodeError("non-minimal encoding")
+ raise DecodeError("non-minimal TAI64NA")
if asecs > 999999999:
raise DecodeError("too many attoseconds")
secs = tai2utc(secs - TAI64Base, leapsecUTCAllow)