|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--sam.cipher.Factory | +--sam.cipher.ReflexiveFactory
Implementation of a Cipher
factory based on reflection.
Registers a new Cipher
class.
Any specialized Key
class associated with the cipher must be declared innerly with a
long[]
constructor.
To be called typically in a static initializer of a subclass, as in:
or alternativelypublic class MyCipher extends Cipher { static { Cipher.register( MyCipher.class, "My cipher", "This is my private key cipher" ); // May throw a Cipher.Error } ... public class Key extends Cipher.Key { public Key(long[] bits) { super(bits); ... } } }
public class MyCipher extends Cipher { static { Cipher.register( new ReflexiveFactory("Mycipher", "This is my own cipher class") { public int getPreferredKeySize(int suggestedSize) { return highestMultiple(suggestedSize, 8); // My cipher requires key lengths be multiple of 8 bits } } ); // May throw a Cipher.Error } ... }
Field Summary |
Fields inherited from class sam.cipher.Factory |
description, name |
Constructor Summary | |
ReflexiveFactory(java.lang.Class cipher,
java.lang.String name,
java.lang.String description)
Makes a new registration entry for a cipher. |
|
ReflexiveFactory(java.lang.String description)
Builds a new reflexive Cipher factory based on the supposedly existing outer class. |
|
ReflexiveFactory(java.lang.String name,
java.lang.String description)
Builds a new reflexive Cipher factory based on the supposedly existing outer class. |
Method Summary | |
protected static java.lang.String |
getBestDescription(java.lang.String description,
java.lang.Class clazz)
Gets the best name for specified cipher class. |
protected static java.lang.String |
getBestName(java.lang.String name,
java.lang.Class clazz)
Gets the best name for specified cipher class. |
protected sam.cipher.Cipher |
make(long[] keyBits,
boolean mode)
Builds a new cipher instance through constructor s found by introspection. |
Methods inherited from class sam.cipher.Factory |
getPreferredKeySize, highestIn, highestMultiple, ranged, resizeKey, resizeKeyToPreferredSize |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ReflexiveFactory(java.lang.String description) throws Cipher.Error
Cipher
factory based on the supposedly existing outer class.
Typical use would be to declare a static inner subclass of ReflexiveFactory
inside your
Cipher
subclass.
description
- a human-readable description of this cipher implementation
Note that the registration name is automatically inferred from the ciphering class name.
Warning using automatic naming based on class name can cause registration name collision !
Warning: this is not a ReflexiveFactory(String className)
constructor !public ReflexiveFactory(java.lang.String name, java.lang.String description) throws Cipher.Error
Cipher
factory based on the supposedly existing outer class.
Typical use would be to declare a static inner subclass of ReflexiveFactory
inside your
Cipher
subclass.
name
- the registration name for this cipher implementation.description
- a human-readable description of this cipher implementationpublic ReflexiveFactory(java.lang.Class cipher, java.lang.String name, java.lang.String description) throws Cipher.Error
The main cipher constructor public Cipher(Cipher.Key)
is obtained by reflection.
The public Key(long[])
constructor is obtained by reflection, either from a declared
inner-class of the cipher
class, or from the default Cipher.Key
class.
cipher
- the cipher class, or null
if to be retrieved automatically through reflection.name
- the registration name of the cipher, or null
if default name.description
- the description to be associated with the cipher, or null
if none.
Cipher.Error
- in case of security or instantiation exceptionsSecurityManager
Method Detail |
protected sam.cipher.Cipher make(long[] keyBits, boolean mode) throws Cipher.Error
constructor
s found by introspection.
make
in class Factory
keyBits
- the key as full long
s, its length having been retrofitted by the
getPreferredKeySize
method.mode
- true
if encrypting, false
otherwise (decrypting).
Cipher.Error
Cipher.ENCRYPT
,
Cipher.DECRYPT
protected static java.lang.String getBestName(java.lang.String name, java.lang.Class clazz)
name
if it is neither null
nor equal to ""
;
otherwise the last part of the class name is used, which includes dot-separated outer-classes
but excludes package specification.
Warning using automatic naming based on class name can cause registration name collision !
protected static java.lang.String getBestDescription(java.lang.String description, java.lang.Class clazz)
name
if it is neither null
nor equal to ""
;
otherwise a default string is used stating that ... no information is available.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |