com.monica.javacom.ssh
Class MJCSSHIO

java.lang.Object
  |
  +--com.monica.javacom.ssh.MJCSSHIO

public class MJCSSHIO
extends java.lang.Object

Class for providing functionality either field conversion to String or from String according to the SSH2 specification, or some aspects of the SSH2 functionality that could not be put into any other class.


Constructor Summary
MJCSSHIO()
           
 
Method Summary
 java.lang.String chosenMatch(java.lang.String s)
          Returns the first element of the comma separated String s, or throws an Exception if s is empty.
 java.lang.String delNextToken(java.lang.String msg, java.lang.String[] spaces)
          This method deletes the left substring of msg that would be returned by getNextToken(msg, spaces) and the separaing space string at the end of the result from getNextToken as well (if there is any).
 java.lang.String findMatch(java.lang.String s1, java.lang.String s2, int pri)
          Let s1 and s2 be two comma separated Strings.
 java.lang.String getNextToken(java.lang.String msg, java.lang.String[] spaces)
          Let msg be a String that can contain separating space Strings.
 java.util.Vector parsePayload(java.lang.String payload, java.lang.String[] desc)
          Parses an unencoded SSH2 payload String and returns a Vector containing the elements of the payload as different Objects.
 java.lang.String print(java.lang.String s)
          Coverts a String s interpreted as an unsigned number in 256 radix to a String r representing an unsigned number in 16 radix with the number signs "0"..."9" and "A"..."F".
 boolean rBoolean(java.lang.String s)
          Creates a boolean from a String encoded as specified in the SSH2 specification and beginning with a BOOLEAN.
 java.math.BigInteger rByte(java.lang.String s)
          Creates a BigInteger from a String ancoded as specified in the SSH2 specification and beginning with an SSH2 BYTE.
 int rByteInt(java.lang.String s)
          Creates an int from a String encoded as specified int the SSH2 specification and beginning with an SSH2 BYTE.
 java.math.BigInteger rMpint(java.lang.String s)
          Creates a BigInteger from a String encoded as specified in the SSH2 specification and beginning with an MPINT.
 java.lang.String rString(java.lang.String s)
          Creates a String from a String encoded as specified in the SSH2 specification and beginning with a STRING.
 java.math.BigInteger rUint32(java.lang.String s)
          Creates a BigInteger from a String encoded as specified in the SSH2 specification and beginning with an UINT32.
 int rUint32Int(java.lang.String s)
          Creates an int from a String encoded as specified in the SSH2 specification and beginning with an UINT32.
 java.math.BigInteger rUint64(java.lang.String s)
          Creates a BigInteger from a String encoed as specified in the SSH2 specification and beginning with an UINT64.
 long rUint64Long(java.lang.String s)
          Creates a long from a String encoed as specified in the SSH2 specification and beginning with an UINT64.
 java.math.BigInteger stringAsBigInteger(java.lang.String s)
          Creates a BigInteger from a String s.
 java.lang.String wBoolean(boolean b)
          Creates a one byte String according to the SSH2 (BOOLEAN) specification from a boolean.
 java.lang.String wByte(int i)
          Creates a one byte String according to the SSH2 (BYTE) specification from an int.
 java.lang.String wLowOrderUint32(int i)
          Creates a four byte String from an int by writing the bytes in the low order way.
 java.lang.String wMpint(java.math.BigInteger bi)
          Creates an arbitrary length String according to the SSH2 (MPINT) specification from a BigInteger.
 java.lang.String wString(java.lang.String s)
          Creates an arbitrary length String according to the SSH2 (STRING) specification from a String.
 java.lang.String wUint32(int i)
          Creates a four byte String according to the SSH2 (UINT32) specification from an int.
 java.lang.String wUint64(long l)
          Creates an eight byte String according to the SSH2 (UINT64) specification from a long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MJCSSHIO

public MJCSSHIO()
Method Detail

wByte

public java.lang.String wByte(int i)
Creates a one byte String according to the SSH2 (BYTE) specification from an int.
Returns:
String: the result

wBoolean

public java.lang.String wBoolean(boolean b)
Creates a one byte String according to the SSH2 (BOOLEAN) specification from a boolean.
Parameters:
boolean - b: the boolean to be converted to String
Returns:
String: the result

wUint32

public java.lang.String wUint32(int i)
Creates a four byte String according to the SSH2 (UINT32) specification from an int.
Parameters:
int - i: the int to be converted to String
Returns:
String: the result

wLowOrderUint32

public java.lang.String wLowOrderUint32(int i)
Creates a four byte String from an int by writing the bytes in the low order way.
Parameters:
int - i: the int to be converted to String
Returns:
String: the result

wUint64

public java.lang.String wUint64(long l)
Creates an eight byte String according to the SSH2 (UINT64) specification from a long.
Parameters:
long - l: the long to be converted to String
Returns:
String: the result

wString

public java.lang.String wString(java.lang.String s)
Creates an arbitrary length String according to the SSH2 (STRING) specification from a String.
Parameters:
String - s: the String to be converted to String
Returns:
String: the result

wMpint

public java.lang.String wMpint(java.math.BigInteger bi)
Creates an arbitrary length String according to the SSH2 (MPINT) specification from a BigInteger.
Parameters:
BigInteger - bi: the BigInteger to be converted to String
Returns:
String: the result

rByte

public java.math.BigInteger rByte(java.lang.String s)
Creates a BigInteger from a String ancoded as specified in the SSH2 specification and beginning with an SSH2 BYTE.
Parameters:
String - s: the String containing the BYTE
Returns:
BigInteger: the BYTE as BigInteger

rByteInt

public int rByteInt(java.lang.String s)
Creates an int from a String encoded as specified int the SSH2 specification and beginning with an SSH2 BYTE.
Parameters:
String - s: the String containing the BYTE
Returns:
int: the BYTE as int

rBoolean

public boolean rBoolean(java.lang.String s)
Creates a boolean from a String encoded as specified in the SSH2 specification and beginning with a BOOLEAN.
Parameters:
String - s: the String containing the BYTE

rUint32

public java.math.BigInteger rUint32(java.lang.String s)
Creates a BigInteger from a String encoded as specified in the SSH2 specification and beginning with an UINT32.
Parameters:
String - s: the String containing the UINT32
Returns:
BigInteger: the UINT32 as BigInteger

rUint32Int

public int rUint32Int(java.lang.String s)
Creates an int from a String encoded as specified in the SSH2 specification and beginning with an UINT32.
Parameters:
String - s: the String containing the UINT32
Returns:
int: the UINT32 as int

rUint64

public java.math.BigInteger rUint64(java.lang.String s)
Creates a BigInteger from a String encoed as specified in the SSH2 specification and beginning with an UINT64.
Parameters:
String - s: the String containing the UINT64
Returns:
BigInteger: the UINT64 as BigInteger

rUint64Long

public long rUint64Long(java.lang.String s)
Creates a long from a String encoed as specified in the SSH2 specification and beginning with an UINT64.
Parameters:
String - s: the String containing the UINT64
Returns:
long: the UINT64 as long

rString

public java.lang.String rString(java.lang.String s)
Creates a String from a String encoded as specified in the SSH2 specification and beginning with a STRING.
Parameters:
String - s: the String containing the STRING
Returns:
String: the STRING as String

rMpint

public java.math.BigInteger rMpint(java.lang.String s)
Creates a BigInteger from a String encoded as specified in the SSH2 specification and beginning with an MPINT.
Parameters:
String - s: the String containing the MPINT
Returns:
BigInteger: the MPINT as BigInteger

parsePayload

public java.util.Vector parsePayload(java.lang.String payload,
                                     java.lang.String[] desc)
Parses an unencoded SSH2 payload String and returns a Vector containing the elements of the payload as different Objects.
Parameters:
String - payload: the full payload String
String[] - desc: the String array describing the payload's structure
  • "B" (BYTE), element type BigInteger
  • "3" (UINT32), element type BigInteger
  • "6" (UINT64), element type BigInteger
  • "M" (MPINT), element type BigInteger
  • "S" (STRING), elemnt type String
  • "O" (BOOLEAN), element type Boolean
  • "Uxxx" (---), element type String, means not SSH2 coded xxx length string
Returns:
Vector: the Vector containing the elements as specified in desc

findMatch

public java.lang.String findMatch(java.lang.String s1,
                                  java.lang.String s2,
                                  int pri)
Let s1 and s2 be two comma separated Strings. The result of this method r is a comma separated String. r contains elements, which are contained in both s1 and s2. The order of the elements in r is either the order of the elements in s1 (pri=1) or the order of the elements in s2 (pri=2).
Parameters:
String - s1: s1
String - s2: s2
int - pri: pri
Returns:
String: r

chosenMatch

public java.lang.String chosenMatch(java.lang.String s)
                             throws java.lang.Exception
Returns the first element of the comma separated String s, or throws an Exception if s is empty.
Parameters:
String - s: the comma separated String
Returns:
String: the first element of s
Throws:
Exception: - is s is empty

getNextToken

public java.lang.String getNextToken(java.lang.String msg,
                                     java.lang.String[] spaces)
Let msg be a String that can contain separating space Strings. The possible separating space Strings are described in spaces. This method returns the smallest left substring of msg that either ends with one of the separating space Strings or if msg does not contain any of the separating space Strings then this method returns msg.
Parameters:
String - msg: msg
String[] - spaces: separating space Strings
Returns:
String: the result as described above

delNextToken

public java.lang.String delNextToken(java.lang.String msg,
                                     java.lang.String[] spaces)
This method deletes the left substring of msg that would be returned by getNextToken(msg, spaces) and the separaing space string at the end of the result from getNextToken as well (if there is any).
Parameters:
String - msg: msg
String[] - spaces: separating space Strings
Returns:
String: the result after the deletion

stringAsBigInteger

public java.math.BigInteger stringAsBigInteger(java.lang.String s)
Creates a BigInteger from a String s. s is interpreted as as an unsigned number in 256 radix. s.charAt(0) is MSB, s.charAt(s.length()-1) is LSB. (s.charAt(i)&0x00ff)>>7 is MSB and s.charAt(i)&0x0001 is LSB.
Parameters:
String - s: String to be interpreted as an unsigned number
Returns:
BigInteger: the result

print

public java.lang.String print(java.lang.String s)
Coverts a String s interpreted as an unsigned number in 256 radix to a String r representing an unsigned number in 16 radix with the number signs "0"..."9" and "A"..."F". r.length()=s.length()*2. r.charAt(i*2)==HEX((s.charAt(i)&0x00f0)>>4), r.charAt(i*2+1)==HEX(s.charAt(i)&0x000f)
Parameters:
String - s: the String to be interpreted as an unsigned number in 256 radix
Returns:
String: the String interpreted as an unsigned number in 16 radix