Class Value

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Value extends ProxyInstance

A value containing a secret

A SecretValue contains a password or other secret value.

Use get() to get the actual secret data, such as a password. The secret data is not necessarily null-terminated, unless the content type is "text/plain".

Each SecretValue has a content type. For passwords, this is text/plain. Use getContentType() to look at the content type.

SecretValue is reference counted and immutable. The secret data is only freed when all references have been released via unref().

  • Constructor Details

    • Value

      public Value(MemorySegment address)
      Create a Value proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Value

      public Value(String secret, long length, String contentType)

      Create a SecretValue for the secret data passed in.

      The secret data is copied into non-pageable 'secure' memory.

      If the length is less than zero, then secret is assumed to be null-terminated.

      Parameters:
      secret - the secret data
      length - the length of the data
      contentType - the content type of the data
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Value class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • full

      public static Value full(String secret, long length, String contentType)

      Create a SecretValue for the secret data passed in.

      The secret data is not copied, and will later be freed with the destroy function.

      If the length is less than zero, then secret is assumed to be null-terminated.

      Parameters:
      secret - the secret data
      length - the length of the data
      contentType - the content type of the data
      Returns:
      the new SecretValue
    • get

      public byte[] get()

      Get the secret data in the SecretValue.

      The value is not necessarily null-terminated unless it was created with Value(String, long, String) or a null-terminated string was passed to full(String, long, String).

      Returns:
      the secret data
    • getContentType

      public String getContentType()
      Get the content type of the secret value, such as text/plain.
      Returns:
      the content type
    • getText

      public @Nullable String getText()

      Get the secret data in the SecretValue if it contains a textual value.

      The content type must be text/plain.

      Returns:
      the value
    • ref

      public Value ref()

      Add another reference to the SecretValue.

      For each reference unref() should be called to unreference the value.

      Returns:
      the value
    • unref

      public void unref()

      Unreference a SecretValue.

      When the last reference is gone, then the value will be freed.

    • unrefToPassword

      public String unrefToPassword(Out<Long> length)
      Unreference a SecretValue and steal the secret data in SecretValue as nonpageable memory.
      Parameters:
      length - the length of the secret
      Returns:
      a new password string stored in nonpageable memory which must be freed with Secret.passwordFree(String) when done
      Since:
      0.19.0