Imported GNU Classpath 0.92
2006-08-14 Mark Wielaard <mark@klomp.org> Imported GNU Classpath 0.92 * HACKING: Add more importing hints. Update automake version requirement. * configure.ac (gconf-peer): New enable AC argument. Add --disable-gconf-peer and --enable-default-preferences-peer to classpath configure when gconf is disabled. * scripts/makemake.tcl: Set gnu/java/util/prefs/gconf and gnu/java/awt/dnd/peer/gtk to bc. Classify gnu/java/security/Configuration.java as generated source file. * gnu/java/lang/management/VMGarbageCollectorMXBeanImpl.java, gnu/java/lang/management/VMMemoryPoolMXBeanImpl.java, gnu/java/lang/management/VMClassLoadingMXBeanImpl.java, gnu/java/lang/management/VMRuntimeMXBeanImpl.java, gnu/java/lang/management/VMMemoryManagerMXBeanImpl.java, gnu/java/lang/management/VMThreadMXBeanImpl.java, gnu/java/lang/management/VMMemoryMXBeanImpl.java, gnu/java/lang/management/VMCompilationMXBeanImpl.java: New VM stub classes. * java/lang/management/VMManagementFactory.java: Likewise. * java/net/VMURLConnection.java: Likewise. * gnu/java/nio/VMChannel.java: Likewise. * java/lang/Thread.java (getState): Add stub implementation. * java/lang/Class.java (isEnum): Likewise. * java/lang/Class.h (isEnum): Likewise. * gnu/awt/xlib/XToolkit.java (getClasspathTextLayoutPeer): Removed. * javax/naming/spi/NamingManager.java: New override for StackWalker functionality. * configure, sources.am, Makefile.in, gcj/Makefile.in, include/Makefile.in, testsuite/Makefile.in: Regenerated. From-SVN: r116139
This commit is contained in:
@@ -47,91 +47,72 @@ import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
|
||||
/**
|
||||
* <p>An object that implements the {@link IKeyPairCodec} operations for the
|
||||
* <i>Raw</i> format to use with DSS keypairs.</p>
|
||||
* An object that implements the {@link IKeyPairCodec} operations for the
|
||||
* <i>Raw</i> format to use with DSS keypairs.
|
||||
*/
|
||||
public class DSSKeyPairRawCodec implements IKeyPairCodec
|
||||
public class DSSKeyPairRawCodec
|
||||
implements IKeyPairCodec
|
||||
{
|
||||
|
||||
// Constants and variables
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// Constructor(s)
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// implicit 0-arguments constructor
|
||||
|
||||
// Class methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// Instance methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// gnu.crypto.keys.IKeyPairCodec interface implementation ------------------
|
||||
|
||||
public int getFormatID()
|
||||
{
|
||||
return RAW_FORMAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns the encoded form of the designated DSS (Digital Signature
|
||||
* Standard) public key according to the <i>Raw</i> format supported by
|
||||
* this library.</p>
|
||||
*
|
||||
* <p>The <i>Raw</i> format for a DSA public key, in this implementation, is
|
||||
* a byte sequence consisting of the following:</p>
|
||||
* Returns the encoded form of the designated DSS (Digital Signature Standard)
|
||||
* public key according to the <i>Raw</i> format supported by this library.
|
||||
* <p>
|
||||
* The <i>Raw</i> format for a DSA public key, in this implementation, is a
|
||||
* byte sequence consisting of the following:
|
||||
* <ol>
|
||||
* <li>4-byte magic consisting of the value of the literal
|
||||
* {@link Registry#MAGIC_RAW_DSS_PUBLIC_KEY},<li>
|
||||
* <li>1-byte version consisting of the constant: 0x01,</li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>p</code> in internet order,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter
|
||||
* <code>p</code>,</li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>q</code>,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter
|
||||
* <code>q</code>,</li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>g</code>,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter
|
||||
* <code>g</code>,</li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>y</code>,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter
|
||||
* <code>y</code>,</li>
|
||||
* <li>4-byte magic consisting of the value of the literal
|
||||
* {@link Registry#MAGIC_RAW_DSS_PUBLIC_KEY},
|
||||
* <li>
|
||||
* <li>1-byte version consisting of the constant: 0x01,</li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>p</code> in internet order,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter <code>p</code>,
|
||||
* </li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>q</code>,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter <code>q</code>,
|
||||
* </li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>g</code>,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter <code>g</code>,
|
||||
* </li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>y</code>,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter <code>y</code>,
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
*
|
||||
* @param key the key to encode.
|
||||
* @return the <i>Raw</i> format encoding of the designated key.
|
||||
* @throws IllegalArgumentException if the designated key is not a DSS
|
||||
* (Digital Signature Standard) one.
|
||||
* (Digital Signature Standard) one.
|
||||
* @see Registry#MAGIC_RAW_DSS_PUBLIC_KEY
|
||||
*/
|
||||
public byte[] encodePublicKey(PublicKey key)
|
||||
{
|
||||
if (!(key instanceof DSSPublicKey))
|
||||
{
|
||||
throw new IllegalArgumentException("key");
|
||||
}
|
||||
if (! (key instanceof DSSPublicKey))
|
||||
throw new IllegalArgumentException("key");
|
||||
|
||||
DSSPublicKey dssKey = (DSSPublicKey) key;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
// magic
|
||||
baos.write(Registry.MAGIC_RAW_DSS_PUBLIC_KEY[0]);
|
||||
baos.write(Registry.MAGIC_RAW_DSS_PUBLIC_KEY[1]);
|
||||
baos.write(Registry.MAGIC_RAW_DSS_PUBLIC_KEY[2]);
|
||||
baos.write(Registry.MAGIC_RAW_DSS_PUBLIC_KEY[3]);
|
||||
|
||||
// version
|
||||
baos.write(0x01);
|
||||
|
||||
// p
|
||||
byte[] buffer = dssKey.getParams().getP().toByteArray();
|
||||
int length = buffer.length;
|
||||
@@ -140,7 +121,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
|
||||
baos.write((length >>> 8) & 0xFF);
|
||||
baos.write(length & 0xFF);
|
||||
baos.write(buffer, 0, length);
|
||||
|
||||
// q
|
||||
buffer = dssKey.getParams().getQ().toByteArray();
|
||||
length = buffer.length;
|
||||
@@ -149,7 +129,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
|
||||
baos.write((length >>> 8) & 0xFF);
|
||||
baos.write(length & 0xFF);
|
||||
baos.write(buffer, 0, length);
|
||||
|
||||
// g
|
||||
buffer = dssKey.getParams().getG().toByteArray();
|
||||
length = buffer.length;
|
||||
@@ -158,7 +137,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
|
||||
baos.write((length >>> 8) & 0xFF);
|
||||
baos.write(length & 0xFF);
|
||||
baos.write(buffer, 0, length);
|
||||
|
||||
// y
|
||||
buffer = dssKey.getY().toByteArray();
|
||||
length = buffer.length;
|
||||
@@ -167,7 +145,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
|
||||
baos.write((length >>> 8) & 0xFF);
|
||||
baos.write(length & 0xFF);
|
||||
baos.write(buffer, 0, length);
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
@@ -178,112 +155,106 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
|
||||
|| k[1] != Registry.MAGIC_RAW_DSS_PUBLIC_KEY[1]
|
||||
|| k[2] != Registry.MAGIC_RAW_DSS_PUBLIC_KEY[2]
|
||||
|| k[3] != Registry.MAGIC_RAW_DSS_PUBLIC_KEY[3])
|
||||
{
|
||||
throw new IllegalArgumentException("magic");
|
||||
}
|
||||
throw new IllegalArgumentException("magic");
|
||||
|
||||
// version
|
||||
if (k[4] != 0x01)
|
||||
{
|
||||
throw new IllegalArgumentException("version");
|
||||
}
|
||||
int i = 5;
|
||||
throw new IllegalArgumentException("version");
|
||||
|
||||
int i = 5;
|
||||
int l;
|
||||
byte[] buffer;
|
||||
|
||||
// p
|
||||
l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
l = k[i++] << 24
|
||||
| (k[i++] & 0xFF) << 16
|
||||
| (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
buffer = new byte[l];
|
||||
System.arraycopy(k, i, buffer, 0, l);
|
||||
i += l;
|
||||
BigInteger p = new BigInteger(1, buffer);
|
||||
|
||||
// q
|
||||
l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
l = k[i++] << 24
|
||||
| (k[i++] & 0xFF) << 16
|
||||
| (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
buffer = new byte[l];
|
||||
System.arraycopy(k, i, buffer, 0, l);
|
||||
i += l;
|
||||
BigInteger q = new BigInteger(1, buffer);
|
||||
|
||||
// g
|
||||
l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
l = k[i++] << 24
|
||||
| (k[i++] & 0xFF) << 16
|
||||
| (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
buffer = new byte[l];
|
||||
System.arraycopy(k, i, buffer, 0, l);
|
||||
i += l;
|
||||
BigInteger g = new BigInteger(1, buffer);
|
||||
|
||||
// y
|
||||
l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
l = k[i++] << 24
|
||||
| (k[i++] & 0xFF) << 16
|
||||
| (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
buffer = new byte[l];
|
||||
System.arraycopy(k, i, buffer, 0, l);
|
||||
i += l;
|
||||
BigInteger y = new BigInteger(1, buffer);
|
||||
|
||||
return new DSSPublicKey(p, q, g, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns the encoded form of the designated DSS (Digital Signature
|
||||
* Standard) private key according to the <i>Raw</i> format supported by
|
||||
* this library.</p>
|
||||
*
|
||||
* <p>The <i>Raw</i> format for a DSA private key, in this implementation, is
|
||||
* a byte sequence consisting of the following:</p>
|
||||
* Returns the encoded form of the designated DSS (Digital Signature Standard)
|
||||
* private key according to the <i>Raw</i> format supported by this library.
|
||||
* <p>
|
||||
* The <i>Raw</i> format for a DSA private key, in this implementation, is a
|
||||
* byte sequence consisting of the following:
|
||||
* <ol>
|
||||
* <li>4-byte magic consisting of the value of the literal
|
||||
* {@link Registry#MAGIC_RAW_DSS_PRIVATE_KEY},<li>
|
||||
* <li>1-byte version consisting of the constant: 0x01,</li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>p</code> in internet order,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter
|
||||
* <code>p</code>,</li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>q</code>,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter
|
||||
* <code>q</code>,</li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>g</code>,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter
|
||||
* <code>g</code>,</li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>x</code>,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter
|
||||
* <code>x</code>,</li>
|
||||
* <li>4-byte magic consisting of the value of the literal
|
||||
* {@link Registry#MAGIC_RAW_DSS_PRIVATE_KEY},
|
||||
* <li>
|
||||
* <li>1-byte version consisting of the constant: 0x01,</li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>p</code> in internet order,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter <code>p</code>,
|
||||
* </li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>q</code>,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter <code>q</code>,
|
||||
* </li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>g</code>,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter <code>g</code>,
|
||||
* </li>
|
||||
* <li>4-byte count of following bytes representing the DSA parameter
|
||||
* <code>x</code>,</li>
|
||||
* <li>n-bytes representation of a {@link BigInteger} obtained by invoking
|
||||
* the <code>toByteArray()</code> method on the DSA parameter <code>x</code>,
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
*
|
||||
* @param key the key to encode.
|
||||
* @return the <i>Raw</i> format encoding of the designated key.
|
||||
* @throws IllegalArgumentException if the designated key is not a DSS
|
||||
* (Digital Signature Standard) one.
|
||||
* (Digital Signature Standard) one.
|
||||
*/
|
||||
public byte[] encodePrivateKey(PrivateKey key)
|
||||
{
|
||||
if (!(key instanceof DSSPrivateKey))
|
||||
{
|
||||
throw new IllegalArgumentException("key");
|
||||
}
|
||||
if (! (key instanceof DSSPrivateKey))
|
||||
throw new IllegalArgumentException("key");
|
||||
|
||||
DSSPrivateKey dssKey = (DSSPrivateKey) key;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
// magic
|
||||
baos.write(Registry.MAGIC_RAW_DSS_PRIVATE_KEY[0]);
|
||||
baos.write(Registry.MAGIC_RAW_DSS_PRIVATE_KEY[1]);
|
||||
baos.write(Registry.MAGIC_RAW_DSS_PRIVATE_KEY[2]);
|
||||
baos.write(Registry.MAGIC_RAW_DSS_PRIVATE_KEY[3]);
|
||||
|
||||
// version
|
||||
baos.write(0x01);
|
||||
|
||||
// p
|
||||
byte[] buffer = dssKey.getParams().getP().toByteArray();
|
||||
int length = buffer.length;
|
||||
@@ -292,7 +263,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
|
||||
baos.write((length >>> 8) & 0xFF);
|
||||
baos.write(length & 0xFF);
|
||||
baos.write(buffer, 0, length);
|
||||
|
||||
// q
|
||||
buffer = dssKey.getParams().getQ().toByteArray();
|
||||
length = buffer.length;
|
||||
@@ -301,7 +271,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
|
||||
baos.write((length >>> 8) & 0xFF);
|
||||
baos.write(length & 0xFF);
|
||||
baos.write(buffer, 0, length);
|
||||
|
||||
// g
|
||||
buffer = dssKey.getParams().getG().toByteArray();
|
||||
length = buffer.length;
|
||||
@@ -310,7 +279,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
|
||||
baos.write((length >>> 8) & 0xFF);
|
||||
baos.write(length & 0xFF);
|
||||
baos.write(buffer, 0, length);
|
||||
|
||||
// x
|
||||
buffer = dssKey.getX().toByteArray();
|
||||
length = buffer.length;
|
||||
@@ -319,7 +287,6 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
|
||||
baos.write((length >>> 8) & 0xFF);
|
||||
baos.write(length & 0xFF);
|
||||
baos.write(buffer, 0, length);
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
@@ -330,52 +297,51 @@ public class DSSKeyPairRawCodec implements IKeyPairCodec
|
||||
|| k[1] != Registry.MAGIC_RAW_DSS_PRIVATE_KEY[1]
|
||||
|| k[2] != Registry.MAGIC_RAW_DSS_PRIVATE_KEY[2]
|
||||
|| k[3] != Registry.MAGIC_RAW_DSS_PRIVATE_KEY[3])
|
||||
{
|
||||
throw new IllegalArgumentException("magic");
|
||||
}
|
||||
throw new IllegalArgumentException("magic");
|
||||
|
||||
// version
|
||||
if (k[4] != 0x01)
|
||||
{
|
||||
throw new IllegalArgumentException("version");
|
||||
}
|
||||
int i = 5;
|
||||
throw new IllegalArgumentException("version");
|
||||
|
||||
int i = 5;
|
||||
int l;
|
||||
byte[] buffer;
|
||||
|
||||
// p
|
||||
l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
l = k[i++] << 24
|
||||
| (k[i++] & 0xFF) << 16
|
||||
| (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
buffer = new byte[l];
|
||||
System.arraycopy(k, i, buffer, 0, l);
|
||||
i += l;
|
||||
BigInteger p = new BigInteger(1, buffer);
|
||||
|
||||
// q
|
||||
l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
l = k[i++] << 24
|
||||
| (k[i++] & 0xFF) << 16
|
||||
| (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
buffer = new byte[l];
|
||||
System.arraycopy(k, i, buffer, 0, l);
|
||||
i += l;
|
||||
BigInteger q = new BigInteger(1, buffer);
|
||||
|
||||
// g
|
||||
l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
l = k[i++] << 24
|
||||
| (k[i++] & 0xFF) << 16
|
||||
| (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
buffer = new byte[l];
|
||||
System.arraycopy(k, i, buffer, 0, l);
|
||||
i += l;
|
||||
BigInteger g = new BigInteger(1, buffer);
|
||||
|
||||
// x
|
||||
l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
l = k[i++] << 24
|
||||
| (k[i++] & 0xFF) << 16
|
||||
| (k[i++] & 0xFF) << 8
|
||||
| (k[i++] & 0xFF);
|
||||
buffer = new byte[l];
|
||||
System.arraycopy(k, i, buffer, 0, l);
|
||||
i += l;
|
||||
BigInteger x = new BigInteger(1, buffer);
|
||||
|
||||
return new DSSPrivateKey(p, q, g, x);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user