Package org.webpki.cbor
Class CBORUtil
java.lang.Object
org.webpki.cbor.CBORUtil
Utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]concatByteArrays(byte[]... listOfArrays) Concatenate a set of byte-arrays.static CBORStringcreateDateTime(OffsetDateTime offsetDateTime, boolean subsecond, boolean utc) CreateDateTimeobject.static CBORObjectcreateEpochTime(Instant instant, boolean subsecond) CreateEpochTimeobject.static byte[]unsignedLongToByteArray(long value) Convertlongtobyte[].
-
Method Details
-
createDateTime
public static CBORString createDateTime(OffsetDateTime offsetDateTime, boolean subsecond, boolean utc) CreateDateTimeobject.This method creates a date/time string in the ISO format described in section 5.6 of [RFC3339]. The string is subsequently wrapped in aCBORStringobject.IfoffsetDateTimeis not within the range"1970-01-01T00:00:00Z"to"9999-12-31T23:59:59Z", aCBORExceptionis thrown .Ifsubsecondistruethe date/time string will feature up to 9 digits of subsecond data (.nnnnnnnnn) as well.Sample code:CBORString dateTime = CBORUtil.createDateTime(OffsetDateTime.now(), true, false);
System.out.println(dateTime.toString()); // Diagnostic notation
"2025-12-05T13:55:42.418+01:00"- Parameters:
offsetDateTime- DateTime source object.subsecond-Ifsubsecondistrue, the subsecond data of theoffsetDateTimeobject will be featured in the created time object. Ifsubsecondisfalseroundimg is performed.utc-Ifutcistrue, theUTCtime zone (denoted by a terminatingZ) will be used, else the local time followed by theUTCoffset (±hh:mm) will be used.- Returns:
CBORString- Throws:
CBORException- See Also:
-
createEpochTime
CreateEpochTimeobject.This method creates an Epoch [TIME] time stamp.Ifinstantis not within the range0("1970-01-01T00:00:00Z") to253402300799("9999-12-31T23:59:59Z"), aCBORExceptionis thrown.IfsubsecondistrueaCBORFloatobject holding seconds with a milliseconds fraction will be created, else aCBORIntobject holding seconds will be created.Sample code:CBORObject epochTime = CBORUtil.createEpochTime(Instant.now(), false);
System.out.println(epochTime.toString()); // Diagnostic notation
1764939916- Parameters:
instant- Time source object.subsecond-Ifsubsecondistrue, the milliseconds ofinstantwill be featured in the created time object. Note: if the millisecond part ofinstantis zero,subsecondis considered to befalse.Ifsubsecondisfalse, the millisecond part ofinstantwill not be used, but may after rounding, add a second to the created time object. Rounding is performed for milliseconds≥500.- Returns:
CBORObject- Throws:
CBORException- See Also:
-
concatByteArrays
public static byte[] concatByteArrays(byte[]... listOfArrays) Concatenate a set of byte-arrays.- Parameters:
listOfArrays- Sort of self-explanatory.- Returns:
byte[]
-
unsignedLongToByteArray
public static byte[] unsignedLongToByteArray(long value) Convertlongtobyte[].- Parameters:
value- Value to be converted.- Returns:
byte[]
-