Package org.apache.sshd.common.signature
Class AbstractSignature
java.lang.Object
org.apache.sshd.common.signature.AbstractSignature
- All Implemented Interfaces:
AlgorithmNameProvider
,Signature
- Direct Known Subclasses:
SignatureDSA
,SignatureECDSA
,SignatureEd25519
,SignatureRSA
Useful base class for
Signature
implementation-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Signature
doInitSignature
(SessionContext session, String algo, Key key, boolean forSigning) Initializes the internal signature instanceprotected boolean
doVerify
(byte[] data) extractEncodedSignature
(byte[] sig, Collection<String> expectedTypes) Makes an attempt to detect if the signature is encoded or pure dataextractEncodedSignature
(byte[] sig, Predicate<? super String> typeSelector) final String
protected Signature
void
initSigner
(SessionContext session, PrivateKey key) void
initVerifier
(SessionContext session, PublicKey key) byte[]
sign
(SessionContext session) Compute the signaturetoString()
void
update
(SessionContext session, byte[] hash, int off, int len) Update the computed signature with the given dataMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.sshd.common.signature.Signature
getSshAlgorithmName, update, verify
-
Field Details
-
signatureInstance
-
algorithm
-
-
Constructor Details
-
AbstractSignature
-
-
Method Details
-
getAlgorithm
- Specified by:
getAlgorithm
in interfaceAlgorithmNameProvider
-
doInitSignature
protected Signature doInitSignature(SessionContext session, String algo, Key key, boolean forSigning) throws GeneralSecurityException Initializes the internal signature instance- Parameters:
session
- TheSessionContext
for calling this method - may benull
if not called within a session contextalgo
- The signature's algorithm namekey
- theKey
that is provided for initialization - aPrivateKey
for signing and aPublicKey
for verificationforSigning
- Iftrue
then it is being initialized for signing, otherwise for verifying a signature- Returns:
- The
Signature
instance - Throws:
GeneralSecurityException
- if failed to initialize
-
getSignature
- Returns:
- The current
Signature
instance -null
if not initialized - See Also:
-
sign
Description copied from interface:Signature
Compute the signature- Specified by:
sign
in interfaceSignature
- Parameters:
session
- TheSessionContext
for calling this method - may benull
if not called within a session context- Returns:
- The signature value
- Throws:
Exception
- If failed to calculate the signature
-
initVerifier
- Specified by:
initVerifier
in interfaceSignature
- Parameters:
session
- TheSessionContext
for calling this method - may benull
if not called within a session contextkey
- ThePublicKey
to be used for verifying signatures- Throws:
Exception
- If failed to initialize
-
initSigner
- Specified by:
initSigner
in interfaceSignature
- Parameters:
session
- TheSessionContext
for calling this method - may benull
if not called within a session contextkey
- ThePrivateKey
to be used for signing- Throws:
Exception
- If failed to initialize
-
update
Description copied from interface:Signature
Update the computed signature with the given data- Specified by:
update
in interfaceSignature
- Parameters:
session
- TheSessionContext
for calling this method - may benull
if not called within a session contexthash
- The hash data bufferoff
- Offset of hash data in bufferlen
- Length of hash data- Throws:
Exception
- If failed to update
-
extractEncodedSignature
protected Map.Entry<String,byte[]> extractEncodedSignature(byte[] sig, Collection<String> expectedTypes) Makes an attempt to detect if the signature is encoded or pure data- Parameters:
sig
- The original signatureexpectedTypes
- The expected encoded key types- Returns:
- A
AbstractMap.SimpleImmutableEntry
where first value is the key type and second value is the data -null
if not encoded
-
extractEncodedSignature
-
doVerify
- Throws:
SignatureException
-
toString
-