net.i2p.sam
Class SAMUtils

java.lang.Object
  extended by net.i2p.sam.SAMUtils

 class SAMUtils
extends Object

Miscellaneous utility methods used by SAM protocol handlers.

Author:
human

Constructor Summary
SAMUtils()
           
 
Method Summary
static boolean checkDestination(String dest)
          Check whether a base64-encoded dest is valid
static boolean checkPrivateDestination(String dest)
          Check whether a base64-encoded {dest,privkey,signingprivkey} is valid
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(StringTokenizer tok)
          Parse SAM parameters, and put them into a Propetries object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SAMUtils

SAMUtils()
Method Detail

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
Since:
0.9.14

checkDestination

public static boolean checkDestination(String dest)
Check whether a base64-encoded dest is valid

Parameters:
dest - The base64-encoded destination to be checked
Returns:
True if the destination is valid, false otherwise

checkPrivateDestination

public static boolean checkPrivateDestination(String dest)
Check whether a base64-encoded {dest,privkey,signingprivkey} is valid

Parameters:
dest - The base64-encoded destination and keys to be checked (same format as PrivateKeyFile)
Returns:
true if valid

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 Base 64 or name not found

parseParams

public static Properties parseParams(StringTokenizer tok)
                              throws SAMException
Parse SAM parameters, and put them into a Propetries object

Parameters:
tok - A StringTokenizer pointing to the SAM parameters
Returns:
Properties with the parsed SAM params, never null
Throws:
SAMException - if the data was formatted incorrectly