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
public abstract class AbstractSignature extends Object implements Signature
Useful base class forSignatureimplementation- Author:
- Apache MINA SSHD Project
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSignature(String algorithm)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected SignaturedoInitSignature(SessionContext session, String algo, Key key, boolean forSigning)Initializes the internal signature instanceprotected booleandoVerify(byte[] data)protected Map.Entry<String,byte[]>extractEncodedSignature(byte[] sig, Collection<String> expectedTypes)Makes an attempt to detect if the signature is encoded or pure dataprotected Map.Entry<String,byte[]>extractEncodedSignature(byte[] sig, Predicate<? super String> typeSelector)StringgetAlgorithm()protected SignaturegetSignature()voidinitSigner(SessionContext session, PrivateKey key)voidinitVerifier(SessionContext session, PublicKey key)byte[]sign(SessionContext session)Compute the signatureStringtoString()voidupdate(SessionContext session, byte[] hash, int off, int len)Update the computed signature with the given data-
Methods 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
-
-
-
-
Constructor Detail
-
AbstractSignature
protected AbstractSignature(String algorithm)
-
-
Method Detail
-
getAlgorithm
public final String getAlgorithm()
- Specified by:
getAlgorithmin interfaceAlgorithmNameProvider
-
doInitSignature
protected Signature doInitSignature(SessionContext session, String algo, Key key, boolean forSigning) throws GeneralSecurityException
Initializes the internal signature instance- Parameters:
session- TheSessionContextfor calling this method - may benullif not called within a session contextalgo- The signature's algorithm namekey- theKeythat is provided for initialization - aPrivateKeyfor signing and aPublicKeyfor verificationforSigning- Iftruethen it is being initialized for signing, otherwise for verifying a signature- Returns:
- The
Signatureinstance - Throws:
GeneralSecurityException- if failed to initialize
-
getSignature
protected Signature getSignature()
- Returns:
- The current
Signatureinstance -nullif not initialized - See Also:
doInitSignature(SessionContext, String, Key, boolean)
-
sign
public byte[] sign(SessionContext session) throws Exception
Description copied from interface:SignatureCompute the signature- Specified by:
signin interfaceSignature- Parameters:
session- TheSessionContextfor calling this method - may benullif not called within a session context- Returns:
- The signature value
- Throws:
Exception- If failed to calculate the signature
-
initVerifier
public void initVerifier(SessionContext session, PublicKey key) throws Exception
- Specified by:
initVerifierin interfaceSignature- Parameters:
session- TheSessionContextfor calling this method - may benullif not called within a session contextkey- ThePublicKeyto be used for verifying signatures- Throws:
Exception- If failed to initialize
-
initSigner
public void initSigner(SessionContext session, PrivateKey key) throws Exception
- Specified by:
initSignerin interfaceSignature- Parameters:
session- TheSessionContextfor calling this method - may benullif not called within a session contextkey- ThePrivateKeyto be used for signing- Throws:
Exception- If failed to initialize
-
update
public void update(SessionContext session, byte[] hash, int off, int len) throws Exception
Description copied from interface:SignatureUpdate the computed signature with the given data- Specified by:
updatein interfaceSignature- Parameters:
session- TheSessionContextfor calling this method - may benullif 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.SimpleImmutableEntrywhere first value is the key type and second value is the data -nullif not encoded
-
extractEncodedSignature
protected Map.Entry<String,byte[]> extractEncodedSignature(byte[] sig, Predicate<? super String> typeSelector)
-
doVerify
protected boolean doVerify(byte[] data) throws SignatureException- Throws:
SignatureException
-
-