KeyMatcherpublic class KeyAddress extends java.lang.Object implements KeyMatcher
AbstractKey that implements AbstractKey.updateDigestWithKeyComponents(Digest) method. The address contains verification code, key type
information and the hash itself. To check that some key matches the address, create KeyAddress instance from
a string or packed bytes and call isMatchingKey(AbstractKey) to check it is ok.
It is possible to keep any 4 bits of extra data, getTypeMark(), which will also be protected by the control
code.
The inner structure is:
First byte: bits 0x-1..0x08 - key type mask (15 types except code 0), bits 0x10..0x80 - mark byte, [0..15]
bytes [1..48]:Sha3_384 digest of the key in question
bytes [49..53]: Crc32 control code of all previous bytes
Packed to string the long address takes 72 characters, short version only 51.
| Modifier and Type | Class | Description |
|---|---|---|
static class |
KeyAddress.IllegalAddressException |
| Constructor | Description |
|---|---|
KeyAddress() |
|
KeyAddress(byte[] packedSource) |
Unpack an address.
|
KeyAddress(AbstractKey key,
int typeMark,
boolean useSha3_384) |
Build new KeyAddrAddress for a given key
|
KeyAddress(java.lang.String packedString) |
Unpack the string-encoded key (it actually uses
Safe58 to encode). |
KeyAddress(net.sergeych.tools.Binder binder) |
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
equals(java.lang.Object obj) |
|
static net.sergeych.biserializer.BiAdapter |
getBiAdapter() |
|
byte[] |
getPacked() |
|
int |
getTypeMark() |
|
int |
hashCode() |
|
boolean |
isLong() |
|
boolean |
isMatchingKey(AbstractKey key) |
Check that the key matches this address, e.g.
|
boolean |
isMatchingKeyAddress(KeyAddress other) |
Check that the address matches key information.
|
protected static int |
mask(AbstractKey k) |
Each supported key has a mask that represents its type.
|
java.lang.String |
toString() |
Get the packed string representaion.
|
public KeyAddress()
public KeyAddress(AbstractKey key, int typeMark, boolean useSha3_384)
key - to calculate address fromtypeMark - any small number between 0 and 15 inclusive to be stored with address (will also be protected)useSha3_384 - use longer but more solid hash which is more resistent to wuantum attackspublic KeyAddress(byte[] packedSource)
throws KeyAddress.IllegalAddressException
getTypeMark() and isMatchingKey(AbstractKey) methods
to retrieve information.packedSource - binary data holding the addressKeyAddress.IllegalAddressException - if the adress is malformed (control code does not match or wrong type code)public KeyAddress(java.lang.String packedString)
throws KeyAddress.IllegalAddressException
Safe58 to encode). See KeyAddress(byte[]) for more.packedString - string with encoded address, use toString() to obtain packed string representationKeyAddress.IllegalAddressException - if the address is malformed (control code is not valid or bad type code)public KeyAddress(net.sergeych.tools.Binder binder)
public boolean isMatchingKey(AbstractKey key)
AbstractKey.updateDigestWithKeyComponents(Digest)isMatchingKey in interface KeyMatcherkey - to checkpublic boolean isMatchingKeyAddress(KeyAddress other)
getTypeMark()! If the
type mark is important, check it by hand. If teh address sizes are different always retuen false, in this case it
is not possible to perform the real check.isMatchingKeyAddress in interface KeyMatcherother - public final boolean isLong()
public final byte[] getPacked()
public final int getTypeMark()
public java.lang.String toString()
Safe58 to encode data provided by the getPacked()toString in class java.lang.Objectprotected static int mask(AbstractKey k)
k - key to calculate mask of.public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic static net.sergeych.biserializer.BiAdapter getBiAdapter()