net.i2p.sam

## Class SAMUtils

- java.lang.Object
- - net.i2p.sam.SAMUtils

-     class SAMUtils
      extends Object

  Miscellaneous utility methods used by SAM protocol handlers.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `COMMAND`
    `static String` | `OPCODE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SAMUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `checkPrivateDestination(String dest)` Check whether a base64-encoded {dest,privkey,signingprivkey[,offlinesig]} is valid This only checks that the length is correct.
    `static void` | `genRandomKey(OutputStream priv, OutputStream pub)` Generate a random destination key using DSA_SHA1 signature type.
    `static void` | `genRandomKey(OutputStream priv, OutputStream pub, SigType sigType)` Generate a random destination key.
    `static Destination` | `getDest(String s)` Resolve the destination from a key or a hostname
    `static Properties` | `parseParams(String args)` Parse SAM parameters, and put them into a Properties object Modified from EepGet.

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

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

- - ### Field Detail

    - #### COMMAND

          public static final String COMMAND

      See Also:
        Constant Field Values

    - #### OPCODE

          public static final String OPCODE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SAMUtils

          SAMUtils()

  - ### Method Detail

    - #### checkPrivateDestination

          public static boolean checkPrivateDestination(String dest)

      Check whether a base64-encoded {dest,privkey,signingprivkey[,offlinesig]} is valid This only checks that the length is correct. It does not validate for pubkey/privkey match, or check the signatures.
      Parameters:
        `dest` - The base64-encoded destination and keys to be checked (same format as PrivateKeyFile)
      Returns:
        true if valid

    - #### genRandomKey

          public static void genRandomKey(OutputStream priv,
                                          OutputStream pub)

      Generate a random destination key using DSA_SHA1 signature type. Caller must close streams. Fails silently.
      Parameters:
        `priv` - Stream used to write the destination and private keys
        `pub` - Stream used to write the destination (may be null)

    - #### genRandomKey

          public static void genRandomKey(OutputStream priv,
                                          OutputStream pub,
                                          SigType sigType)

      Generate a random destination key. Caller must close streams. Fails silently.
      Parameters:
        `priv` - Stream used to write the destination and private keys
        `pub` - Stream used to write the destination (may be null)
        `sigType` - what signature type

    - #### getDest

          public static Destination getDest(String s)
                                     throws DataFormatException

      Resolve the destination from a key or a hostname
      Parameters:
        `s` - Hostname or key to be resolved
      Returns:
        the Destination for the specified hostname, non-null
      Throws:
        `DataFormatException` - on bad Base64 or name not found

    - #### parseParams

          public static Properties parseParams(String args)
                                        throws SAMException

      Parse SAM parameters, and put them into a Properties object Modified from EepGet. COMMAND and OPCODE are mapped to upper case; keys, values, and ping data are not. Double quotes around values are stripped. Possible input:

            COMMAND
            COMMAND OPCODE
            COMMAND OPCODE [key=val]...
            COMMAND OPCODE [key=" val with spaces "]...
            PING
            PONG
            PING any   thing goes
            PONG any   thing   goes

            Escaping is allowed with a backslash, e.g. \"
            No spaces before or after '=' allowed
            Keys may not be quoted
            COMMAND, OPCODE, and keys may not have '=' or whitespace unless escaped
            Duplicate keys not allowed

      A key without a value is not allowed by the spec, but is returned with the value "true". COMMAND is returned as the value of the key ""COMMAND"". OPCODE, or the remainder of the PING/PONG line if any, is returned as the value of the key ""OPCODE"".
      Parameters:
        `args` - non-null
      Returns:
        non-null, may be empty. Does not throw on missing COMMAND or OPCODE; caller must check.
      Throws:
        `SAMException` - on some errors but not all