diff --git a/core/java/src/net/i2p/data/EncryptedLeaseSet.java b/core/java/src/net/i2p/data/EncryptedLeaseSet.java index 23de3e945393bc5fe1536fd106f7b7c43a3f1e05..d7bac9f2aaf67d54eba6812be7955a326c7d2093 100644 --- a/core/java/src/net/i2p/data/EncryptedLeaseSet.java +++ b/core/java/src/net/i2p/data/EncryptedLeaseSet.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import net.i2p.crypto.SHA256Generator; import net.i2p.crypto.SigType; import net.i2p.util.Clock; @@ -18,6 +19,8 @@ public class EncryptedLeaseSet extends LeaseSet2 { // includes IV and MAC private byte[] _encryptedData; + private LeaseSet2 _decryptedLS2; + private Hash __calculatedHash; private static final int MIN_ENCRYPTED_SIZE = 8 + 16; private static final int MAX_ENCRYPTED_SIZE = 4096; @@ -33,6 +36,24 @@ public class EncryptedLeaseSet extends LeaseSet2 { return KEY_TYPE_ENCRYPTED_LS2; } + /** + * @return 0-16, or 0 if not decrypted. + */ + @Override + public int getLeaseCount() { + // TODO attempt decryption + return _decryptedLS2 != null ? _decryptedLS2.getLeaseCount() : 0; + } + + /** + * @return null if not decrypted. + */ + @Override + public Lease getLease(int index) { + // TODO attempt decryption + return _decryptedLS2 != null ? _decryptedLS2.getLease(index) : null; + } + /** * This does NOT validate the signature * @@ -156,6 +177,27 @@ public class EncryptedLeaseSet extends LeaseSet2 { return rv; } + /** + * Overridden because we have a blinded key, not a dest. + * This is the hash of the signing public key type and the signing public key. + * Throws IllegalStateException if not initialized. + * + * @throws IllegalStateException + */ + @Override + public Hash getHash() { + if (__calculatedHash == null) { + if (_signingKey == null) + throw new IllegalStateException(); + int len = _signingKey.length(); + byte[] b = new byte[2 + len]; + DataHelper.toLong(b, 0, 2, _signingKey.getType().getCode()); + System.arraycopy(_signingKey.getData(), 0, b, 2, len); + __calculatedHash = SHA256Generator.getInstance().calculateHash(b); + } + return __calculatedHash; + } + // encrypt / decrypt TODO @Override