Class ByteArray

  • All Implemented Interfaces:
    com.yubico.internal.util.json.JsonStringSerializable, java.lang.Comparable<ByteArray>

    public final class ByteArray
    extends java.lang.Object
    implements java.lang.Comparable<ByteArray>, com.yubico.internal.util.json.JsonStringSerializable
    An immutable byte array with support for encoding/decoding to/from various encodings.
    • Constructor Detail

      • ByteArray

        public ByteArray​(@NonNull
                         @lombok.NonNull byte[] bytes)
        Create a new instance by copying the contents of bytes.
    • Method Detail

      • fromBase64

        public static ByteArray fromBase64​(@NonNull
                                           @NonNull java.lang.String base64)
        Create a new instance by decoding base64 as classic Base64 data.
      • fromBase64Url

        public static ByteArray fromBase64Url​(@NonNull
                                              @NonNull java.lang.String base64)
                                       throws Base64UrlException
        Create a new instance by decoding base64 as Base64Url data.
        Throws:
        Base64UrlException - if base64 is not valid Base64Url data.
      • fromHex

        public static ByteArray fromHex​(@NonNull
                                        @NonNull java.lang.String hex)
                                 throws HexException
        Create a new instance by decoding hex as hexadecimal data.
        Throws:
        HexException - if hex is not valid hexadecimal data.
      • concat

        public ByteArray concat​(@NonNull
                                @NonNull ByteArray tail)
        Returns:
        a new instance containing a copy of this instance followed by a copy of tail .
      • isEmpty

        public boolean isEmpty()
      • size

        public int size()
      • getBytes

        public byte[] getBytes()
        Returns:
        a copy of the raw byte contents.
      • getBase64

        public java.lang.String getBase64()
        Returns:
        the content bytes encoded as classic Base64 data.
      • getBase64Url

        public java.lang.String getBase64Url()
        Returns:
        the content bytes encoded as Base64Url data.
      • getHex

        public java.lang.String getHex()
        Returns:
        the content bytes encoded as hexadecimal data.
      • toJsonString

        public java.lang.String toJsonString()
        Used by JSON serializer.
        Specified by:
        toJsonString in interface com.yubico.internal.util.json.JsonStringSerializable
      • compareTo

        public int compareTo​(ByteArray other)
        Specified by:
        compareTo in interface java.lang.Comparable<ByteArray>
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object