Package anbxj

Class Crypto_SignedObject

java.lang.Object
anbxj.Crypto_SignedObject
All Implemented Interfaces:
Serializable

public class Crypto_SignedObject extends Object implements Serializable
A serializer-neutral signed container.

The class can hold either a raw SignedObject (JavaSer mode) or the plain fields content, signature, algorithm (ProtoBuf / byte-oriented modes). The generated protocol code always uses this class regardless of the serialiser, and the library methods that consume/produce Crypto_SignedObject select the correct internal representation automatically.

See Also:
  • Constructor Details

    • Crypto_SignedObject

      public Crypto_SignedObject(byte[] content, byte[] signature, String algorithm)
      Creates an instance from raw fields (ProtoBufNew / byte-oriented mode).

      The internal SignedObject is set to null. All three fields are cloned to ensure immutability.

      Parameters:
      content - the serialised content that was signed (must not be null)
      signature - the raw signature bytes (must not be null)
      algorithm - the signature algorithm name, e.g. "SHA256withRSA" (must not be null)
      Throws:
      NullPointerException - if any argument is null
    • Crypto_SignedObject

      public Crypto_SignedObject(SignedObject so)
      Creates an instance from an existing SignedObject (JavaSer mode).

      The raw fields are extracted immediately via Crypto_SerializationUtils.serialize(Object) and SignedObject.getSignature() / SignedObject.getAlgorithm(). The original SignedObject is retained for possible later conversion back to a real SignedObject if needed by the JavaSer verification path.

      Parameters:
      so - the signed object to wrap (must not be null)
      Throws:
      AnBx_LibraryException - if extraction of the inner object, signature, or algorithm fails
      NullPointerException - if so is null
    • Crypto_SignedObject

      public Crypto_SignedObject(AnBx_WireFormats.SignedMessage sm)
      Creates an instance from the Protobuf message wrapper.

      This constructor is used by the typed-Protobuf serializer to reconstruct a Crypto_SignedObject from the fields of a AnBx_WireFormats.SignedMessage.

      Parameters:
      sm - the protobuf message wrapper (must not be null)
      Throws:
      NullPointerException - if sm is null
  • Method Details

    • getContent

      public byte[] getContent()
      Returns a copy of the signed content bytes.

      The returned array is a fresh clone - modifications to it will not affect the internal state of this object.

      Returns:
      the serialised content that was signed (never null)
    • getSignature

      public byte[] getSignature()
      Returns a copy of the raw signature bytes.

      The returned array is a fresh clone - modifications to it will not affect the internal state of this object.

      Returns:
      the signature bytes (never null)
    • getAlgorithm

      public String getAlgorithm()
      Returns the signature algorithm name.

      Example values are "SHA256withRSA", "SHA256withECDSA", etc.

      Returns:
      the algorithm name (never null)
    • getSignedObject

      public SignedObject getSignedObject()
      Returns the original SignedObject if this instance was created from one (JavaSer mode), otherwise null.

      This allows the verification path to use the legacy SignedObject directly when available, avoiding an expensive reconstruction.

      Returns:
      the original SignedObject, or null if the instance was created from raw fields (ProtoBuf / byte-oriented modes)
    • toSignedMessage

      public AnBx_WireFormats.SignedMessage toSignedMessage()
      Converts this container to a Protobuf-compatible AnBx_WireFormats.SignedMessage.

      The returned message holds the same content, signature and algorithm as this object, and can be used directly by the typed Protobuf serialiser.

      Returns:
      a new SignedMessage (never null)
    • toSignedObject

      public SignedObject toSignedObject()
      Reconstructs a SignedObject from this container.

      This is only possible if the instance was originally created from a real SignedObject (JavaSer mode). In that case the original object is returned directly. If the instance was built from raw signature bytes (ProtoBuf / byte-oriented mode), the conversion cannot be performed and an UnsupportedOperationException is thrown.

      Returns:
      the original SignedObject
      Throws:
      UnsupportedOperationException - if the instance was not built from a real SignedObject (i.e. getSignedObject() returns null)
    • toByteArray

      public byte[] toByteArray()
      Produces a deterministic byte array representation of this signed object.

      The binary layout is identical to that produced by AnBx_WireFormats.SignedMessage.toByteArray(). This method is intended for use in Protobuf / byte-oriented serialisation modes where a canonical, language-agnostic format is required.

      Returns:
      the serialised bytes (never null)
      See Also:
    • toProtobufSigned

      public static AnBx_WireFormats.SignedMessage toProtobufSigned(Crypto_SignedObject obj)
      Converts a Crypto_SignedObject to its Protobuf AnBx_WireFormats.SignedMessage representation.
      Parameters:
      obj - the signed object to convert
      Returns:
      the corresponding SignedMessage
    • fromProtobufSigned

      public static Crypto_SignedObject fromProtobufSigned(AnBx_WireFormats.SignedMessage msg)
      Reconstructs a Crypto_SignedObject from a Protobuf AnBx_WireFormats.SignedMessage.
      Parameters:
      msg - the Protobuf message
      Returns:
      the reconstructed container
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object