Class KeysetHandle.Builder
- java.lang.Object
-
- com.google.crypto.tink.KeysetHandle.Builder
-
- Enclosing class:
- KeysetHandle
public static final class KeysetHandle.Builder extends java.lang.ObjectUsed to create newKeysetHandleobjects.A builder can be used to create a new
KeysetHandleobject. To create a builder with an empty keyset, one callsKeysetHandle.newBuilder();. To create a builder from an existing keyset, one callsKeysetHandle.newBuilder(keyset);.To add a new key to a
Builder, one callsaddEntry(com.google.crypto.tink.KeysetHandle.Builder.Entry)with a KeysetEntry object. Such objects can be created- From a named
ParameterswithKeysetHandle.generateEntryFromParametersName(java.lang.String), - From a
Parametersobject, withKeysetHandle.generateEntryFromParameters(com.google.crypto.tink.Parameters), - By importing an existing key, with
KeysetHandle.importKey(com.google.crypto.tink.Key)
All these functions return a
KeysetBuilder.Entry. It is necessary to assign an ID to a new entry by calling one ofKeysetHandle.Builder.Entry.withFixedId(int)orKeysetHandle.Builder.Entry.withRandomId(). The exception is when an existing key which has an id requirement is imported (in which case the required ID is used).It is possible to set the status of an entry by calling
KeysetHandle.Builder.Entry.setStatus(com.google.crypto.tink.KeyStatus). The Status defaults toENABLED.It is possible to set whether an entry is the primary by calling
KeysetHandle.Builder.Entry.makePrimary(). The user must ensure that oncebuild()is called, a primary has been set.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classKeysetHandle.Builder.EntryOne entry, representing a single key, in a Keyset.Builder.
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description KeysetHandle.BuilderaddEntry(KeysetHandle.Builder.Entry entry)Adds an entry to a keysetKeysetHandlebuild()Creates a newKeysetHandle.KeysetHandle.BuilderdeleteAt(int i)Deletes the entry at indexi.KeysetHandle.Builder.EntrygetAt(int i)Returns the entry at index i, 0 <= i < size().KeysetHandle.Builder.EntryremoveAt(int i)Deprecated.UsedeleteAt(int)orgetAt(int)instead.KeysetHandle.BuildersetMonitoringAnnotations(MonitoringAnnotations annotations)Sets MonitoringAnnotations.intsize()Returns the number of entries in this builder.
-
-
-
Method Detail
-
addEntry
@CanIgnoreReturnValue public KeysetHandle.Builder addEntry(KeysetHandle.Builder.Entry entry)
Adds an entry to a keyset
-
setMonitoringAnnotations
@CanIgnoreReturnValue @Alpha public KeysetHandle.Builder setMonitoringAnnotations(MonitoringAnnotations annotations)
Sets MonitoringAnnotations. If not called, then the default value ofMonitoringAnnotations.EMPTYis used.When called twice, the last submitted annotations are used to create the keyset. This method is not thread-safe, and in case of multithreaded access it cannot be guaranteed which annotations get set.
-
size
public int size()
Returns the number of entries in this builder.
-
getAt
public KeysetHandle.Builder.Entry getAt(int i)
Returns the entry at index i, 0 <= i < size().- Throws:
java.lang.IndexOutOfBoundsException- if i < 0 or i >= size();
-
removeAt
@CanIgnoreReturnValue @Deprecated public KeysetHandle.Builder.Entry removeAt(int i)
Deprecated.UsedeleteAt(int)orgetAt(int)instead.Removes the entry at indexiand returns that entry. Shifts any subsequent entries to the left (subtracts one from their indices).
-
deleteAt
@CanIgnoreReturnValue public KeysetHandle.Builder deleteAt(int i)
Deletes the entry at indexi. Shifts any subsequent entries to the left (subtracts one from their indices).
-
build
public KeysetHandle build() throws java.security.GeneralSecurityException
Creates a newKeysetHandle.Throws a
GeneralSecurityExceptionif one of the following holds- No entry was marked as primary
- There is an entry in which the ID has not been set and which did not have a predefined
ID (see
KeysetHandle.Builder.Entry). - There is a
withRandomId-entry which is followed by a nonwithRandomId-entry - There are two entries with the same
withFixedId(including pre-existing keys and imported keys which have an id requirement). build()was previously called forwithRandomIdentries, and hence callingbuild()twice would result in a keyset with different key IDs.- The primary key is not enabled
- Throws:
java.security.GeneralSecurityException
-
-