OpaqueBytes
Keywords: net.corda.core.utilities.OpaqueBytes class
Date: 2023-09-18

net.corda.core.utilities

## Class OpaqueBytes

- net.corda.core.utilities.ByteSequence
- - net.corda.core.utilities.OpaqueBytes

- Direct Known Subclasses:
    DigitalSignature, PrivacySalt, SecureHash, SerializedBytes

      public class OpaqueBytes
      extends ByteSequence

  A simple class that wraps a byte array and makes the equals/hashCode/toString methods work as you actually expect. In an ideal JVM this would be a value type and be completely overhead free. Project Valhalla is adding such functionality to Java, but it won't arrive for a few years yet!

- - ### Field Detail

    - #### Companion

          public static net.corda.core.utilities.OpaqueBytes.Companion Companion

  - ### Constructor Detail

    - #### OpaqueBytes

          public OpaqueBytes(@NotNull
                             kotlin.Array[] bytes)

      A simple class that wraps a byte array and makes the equals/hashCode/toString methods work as you actually expect. In an ideal JVM this would be a value type and be completely overhead free. Project Valhalla is adding such functionality to Java, but it won't arrive for a few years yet!

  - ### Method Detail

    - #### getBytes

          @NotNull
          public kotlin.Array[] getBytes()

      The bytes are always cloned so that this object becomes immutable. This has been done to prevent tampering with entities such as `class SecureHash` and `class PrivacySalt`, as well as preserve the integrity of our hash constants net.corda.core.crypto.SecureHash.zeroHash and net.corda.core.crypto.SecureHash.allOnesHash.

      Cloning like this may become a performance issue, depending on whether or not the JIT compiler is ever able to optimise away the clone. In which case we may need to revisit this later.

      See Also:
        `class SecureHash`, `class PrivacySalt`

    - #### of

          @JvmStatic
           @NotNull
          public static OpaqueBytes of(@NotNull
                                                            byte... b)

      Create `class OpaqueBytes` from a sequence of Byte values.

      See Also:
        `class OpaqueBytes`, Byte