Package org.drasyl.identity
Class IdentityManager
- java.lang.Object
-
- org.drasyl.identity.IdentityManager
-
public class IdentityManager extends Object
This class holds the identity of the node. Messages to the node are addressed to the identity. In a future release, messages will be signed and encrypted with public-private key pairs contained in the identity.
-
-
Field Summary
Fields Modifier and Type Field Description static byte
POW_DIFFICULTY
-
Constructor Summary
Constructors Constructor Description IdentityManager(DrasylConfig config)
Manages the identity at the specified file path.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
deleteIdentityFile(Path path)
Deletes the identity file specified in the configuration.static Identity
generateIdentity()
Generates a new random identity.Identity
getIdentity()
CompressedPrivateKey
getPrivateKey()
ProofOfWork
getProofOfWork()
CompressedPublicKey
getPublicKey()
void
loadOrCreateIdentity()
Attempts to load the identity defined in the configuration: First it tries to read the key pair directly from the configuration.
-
-
-
Constructor Detail
-
IdentityManager
public IdentityManager(DrasylConfig config)
Manages the identity at the specified file path. If there is no identity at this file path yet, a new one is created.
-
-
Method Detail
-
loadOrCreateIdentity
public void loadOrCreateIdentity() throws IOException
Attempts to load the identity defined in the configuration: First it tries to read the key pair directly from the configuration. If no key pair is specified there, the identity is loaded from the identity file path specified in the configuration. If the file does not exist, a new identity is generated and written to the file. If all this fails and no identity can be loaded, anIOException
is thrown.- Throws:
IOException
- if identity could not be loaded or created
-
generateIdentity
public static Identity generateIdentity() throws IOException
Generates a new random identity.- Returns:
- the generated identity
- Throws:
IOException
- if an identity could not be generated
-
getPublicKey
public CompressedPublicKey getPublicKey()
-
getPrivateKey
public CompressedPrivateKey getPrivateKey()
-
getProofOfWork
public ProofOfWork getProofOfWork()
-
getIdentity
public Identity getIdentity()
- Returns:
- returns the node identity.
-
deleteIdentityFile
public static void deleteIdentityFile(Path path) throws IOException
Deletes the identity file specified in the configuration.ATTENTION: Messages directed to the present identity can then no longer be decrypted and read. This step is irreversible. Should only be used if the present identity should never be used again!
- Throws:
IOException
- if identity file could not be deleted
-
-