From 2a5ed938bb33d04e7407160102b19f2e56ef2e9c Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Thu, 2 Jun 2011 13:34:26 +0000 Subject: [PATCH] update generateKeyPair() return type to make it easier --- .../java/src/net/i2p/crypto/KeyGenerator.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/java/src/net/i2p/crypto/KeyGenerator.java b/core/java/src/net/i2p/crypto/KeyGenerator.java index 7853063f32..689516be05 100644 --- a/core/java/src/net/i2p/crypto/KeyGenerator.java +++ b/core/java/src/net/i2p/crypto/KeyGenerator.java @@ -20,6 +20,7 @@ import net.i2p.data.SessionKey; import net.i2p.data.Signature; import net.i2p.data.SigningPrivateKey; import net.i2p.data.SigningPublicKey; +import net.i2p.data.SimpleDataStructure; import net.i2p.util.Clock; import net.i2p.util.Log; import net.i2p.util.NativeBigInteger; @@ -29,18 +30,17 @@ import net.i2p.util.RandomSource; * @author jrandom */ public class KeyGenerator { - private Log _log; - private I2PAppContext _context; + private final Log _log; + private final I2PAppContext _context; public KeyGenerator(I2PAppContext context) { _log = context.logManager().getLog(KeyGenerator.class); _context = context; } + public static KeyGenerator getInstance() { return I2PAppContext.getGlobalContext().keyGenerator(); } - - /** Generate a private 256 bit session key * @return session key @@ -84,11 +84,11 @@ public class KeyGenerator { * index 1 is a PrivateKey * @return pair of keys */ - public Object[] generatePKIKeypair() { + public SimpleDataStructure[] generatePKIKeypair() { BigInteger a = new NativeBigInteger(PUBKEY_EXPONENT_SIZE, _context.random()); BigInteger aalpha = CryptoConstants.elgg.modPow(a, CryptoConstants.elgp); - Object[] keys = new Object[2]; + SimpleDataStructure[] keys = new SimpleDataStructure[2]; keys[0] = new PublicKey(); keys[1] = new PrivateKey(); byte[] k0 = aalpha.toByteArray(); @@ -97,8 +97,8 @@ public class KeyGenerator { // bigInteger.toByteArray returns SIGNED integers, but since they'return positive, // signed two's complement is the same as unsigned - ((PublicKey) keys[0]).setData(padBuffer(k0, PublicKey.KEYSIZE_BYTES)); - ((PrivateKey) keys[1]).setData(padBuffer(k1, PrivateKey.KEYSIZE_BYTES)); + keys[0].setData(padBuffer(k0, PublicKey.KEYSIZE_BYTES)); + keys[1].setData(padBuffer(k1, PrivateKey.KEYSIZE_BYTES)); return keys; } @@ -120,8 +120,8 @@ public class KeyGenerator { * index 1 is a SigningPrivateKey * @return pair of keys */ - public Object[] generateSigningKeypair() { - Object[] keys = new Object[2]; + public SimpleDataStructure[] generateSigningKeypair() { + SimpleDataStructure[] keys = new SimpleDataStructure[2]; BigInteger x = null; // make sure the random key is less than the DSA q @@ -135,8 +135,8 @@ public class KeyGenerator { byte k0[] = padBuffer(y.toByteArray(), SigningPublicKey.KEYSIZE_BYTES); byte k1[] = padBuffer(x.toByteArray(), SigningPrivateKey.KEYSIZE_BYTES); - ((SigningPublicKey) keys[0]).setData(k0); - ((SigningPrivateKey) keys[1]).setData(k1); + keys[0].setData(k0); + keys[1].setData(k1); return keys; } -- GitLab