Package tigase.form

# Class SignatureCalculator

java.lang.Object
tigase.form.SignatureCalculator

public class SignatureCalculator extends Object

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `SUPPORTED_TYPE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SignatureCalculator()`
  `SignatureCalculator(String oauthConsumerKey, String oauthConsumerSecret)`
  `SignatureCalculator(String oauthToken, String oauthTokenSecret, String oauthConsumerKey, String oauthConsumerSecret)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addEmptyFields(Form form)`
  `String`
  `calculateSignature(JID to, Form form)`
  Calculate signature of given form.
  `protected static String`
  `escape(String s)`
  `String`
  `getOauthConsumerKey()`
  `String`
  `getOauthConsumerSecret()`
  `String`
  `getOauthToken()`
  `String`
  `getOauthTokenSecret()`
  `protected byte[]`
  `h(byte[] data)`
  `protected static byte[]`
  `hmac(SecretKey key, byte[] data)`
  `boolean`
  `isMethodSupported(String fOauthSignatureMethod)`
  `protected SecretKey`
  `key(byte[] key)`
  `protected String`
  `randomString()`
  `void`
  `setOauthConsumerKey(String oauthConsumerKey)`
  `void`
  `setOauthConsumerSecret(String oauthConsumerSecret)`
  `void`
  `setOauthToken(String oauthToken)`
  `void`
  `setOauthTokenSecret(String oauthTokenSecret)`
  `void`
  `sign(JID to, String nonce, long timestamp, Form form)`
  Sign given Form.
  `void`
  `sign(JID to, Form form)`
  Sign given form with current time.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### SUPPORTED_TYPE

    public static final String SUPPORTED_TYPE
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### SignatureCalculator

    public SignatureCalculator()

  - ### SignatureCalculator

    public SignatureCalculator(String oauthConsumerKey, String oauthConsumerSecret)

  - ### SignatureCalculator

    public SignatureCalculator(String oauthToken, String oauthTokenSecret, String oauthConsumerKey, String oauthConsumerSecret)

- ## Method Details

  - ### escape

    protected static String escape(String s)

  - ### hmac

    protected static byte[] hmac(SecretKey key, byte[] data) throws NoSuchAlgorithmException, InvalidKeyException
    Throws:
      `NoSuchAlgorithmException`
      `InvalidKeyException`

  - ### addEmptyFields

    public void addEmptyFields(Form form)

  - ### calculateSignature

    public String calculateSignature(JID to, Form form) throws InvalidKeyException, NoSuchAlgorithmException
    Calculate signature of given form. Form will not be changed.
    Parameters:
      `to` - the full destination address, including resource, if any.
      `form` - form to sign.
    Returns:
      Signature of form.
    Throws:
      `InvalidKeyException`
      `NoSuchAlgorithmException`

  - ### getOauthConsumerKey

    public String getOauthConsumerKey()
    Returns:
      the oauthConsumerKey

  - ### setOauthConsumerKey

    public void setOauthConsumerKey(String oauthConsumerKey)
    Parameters:
      `oauthConsumerKey` - the oauthConsumerKey to set

  - ### getOauthConsumerSecret

    public String getOauthConsumerSecret()
    Returns:
      the oauthConsumerSecret

  - ### setOauthConsumerSecret

    public void setOauthConsumerSecret(String oauthConsumerSecret)
    Parameters:
      `oauthConsumerSecret` - the oauthConsumerSecret to set

  - ### getOauthToken

    public String getOauthToken()
    Returns:
      the oauthToken

  - ### setOauthToken

    public void setOauthToken(String oauthToken)
    Parameters:
      `oauthToken` - the oauthToken to set

  - ### getOauthTokenSecret

    public String getOauthTokenSecret()
    Returns:
      the oauthTokenSecret

  - ### setOauthTokenSecret

    public void setOauthTokenSecret(String oauthTokenSecret)
    Parameters:
      `oauthTokenSecret` - the oauthTokenSecret to set

  - ### isMethodSupported

    public boolean isMethodSupported(String fOauthSignatureMethod)

  - ### sign

    public void sign(JID to, Form form) throws InvalidKeyException, NoSuchAlgorithmException
    Sign given form with current time. Signature will be added to form.
    Parameters:
      `to` - the full destination address, including resource, if any.
      `form` - form to sign.
    Throws:
      `InvalidKeyException`
      `NoSuchAlgorithmException`

  - ### sign

    public void sign(JID to, String nonce, long timestamp, Form form) throws InvalidKeyException, NoSuchAlgorithmException
    Sign given Form. Signature will be added to form.
    Parameters:
      `to` - the full destination address, including resource, if any.
      `nonce` - A nonce value that the client has to set. Can be a random alphanumerical string.
      `timestamp` - Number of seconds since 1st of January 1970, 00:00:00 GMT. The client has to set this at the time of signature.
      `form` - form to sign.
    Throws:
      `InvalidKeyException`
      `NoSuchAlgorithmException`

  - ### h

    protected byte[] h(byte[] data) throws NoSuchAlgorithmException
    Throws:
      `NoSuchAlgorithmException`

  - ### key

    protected SecretKey key(byte[] key)

  - ### randomString

    protected String randomString()