Data: Cache data for per-client auth

This commit is contained in:
zzz
2019-05-22 16:01:10 +00:00
parent 62649a6343
commit cb762356da

View File

@ -24,12 +24,38 @@ public class BlindData {
private Destination _dest; private Destination _dest;
private long _routingKeyGenMod; private long _routingKeyGenMod;
/**
* bits 3-0 including per-client bit
* @since 0.9.41
*/
public static final int AUTH_NONE = 0;
/**
* bits 3-0 including per-client bit
* @since 0.9.41
*/
public static final int AUTH_DH = 1;
/**
* bits 3-0 including per-client bit
* @since 0.9.41
*/
public static final int AUTH_PSK = 3;
/** /**
* @param secret may be null or zero-length * @param secret may be null or zero-length
* @throws IllegalArgumentException on various errors * @throws IllegalArgumentException on various errors
*/ */
public BlindData(I2PAppContext ctx, Destination dest, SigType blindType, String secret) { public BlindData(I2PAppContext ctx, Destination dest, SigType blindType, String secret) {
this(ctx, dest.getSigningPublicKey(), blindType, secret); this(ctx, dest, blindType, secret, AUTH_NONE, null);
}
/**
* @param secret may be null or zero-length
* @throws IllegalArgumentException on various errors
* @since 0.9.41
*/
public BlindData(I2PAppContext ctx, Destination dest, SigType blindType, String secret,
int authType, PrivateKey authKey) {
this(ctx, dest.getSigningPublicKey(), blindType, secret, authType, authKey);
_dest = dest; _dest = dest;
} }
@ -38,12 +64,25 @@ public class BlindData {
* @throws IllegalArgumentException on various errors * @throws IllegalArgumentException on various errors
*/ */
public BlindData(I2PAppContext ctx, SigningPublicKey spk, SigType blindType, String secret) { public BlindData(I2PAppContext ctx, SigningPublicKey spk, SigType blindType, String secret) {
this(ctx, spk, blindType, secret, AUTH_NONE, null);
}
/**
* @param secret may be null or zero-length
* @throws IllegalArgumentException on various errors
* @since 0.9.41
*/
public BlindData(I2PAppContext ctx, SigningPublicKey spk, SigType blindType, String secret,
int authType, PrivateKey authKey) {
_context = ctx; _context = ctx;
_clearSPK = spk; _clearSPK = spk;
_blindType = blindType; _blindType = blindType;
_secret = secret; _secret = secret;
_authType = -1; if ((authType != AUTH_NONE && authKey == null) ||
_authKey = null; (authType == AUTH_NONE && authKey != null))
throw new IllegalArgumentException();
_authType = authType;
_authKey = authKey;
// defer until needed // defer until needed
//calculate(); //calculate();
} }
@ -122,7 +161,7 @@ public class BlindData {
} }
/** /**
* @return -1 for no client auth * @return 0 for no client auth, 1 for DH, 3 for PSK
*/ */
public int getAuthType() { public int getAuthType() {
return _authType; return _authType;
@ -170,7 +209,7 @@ public class BlindData {
if (_secret != null) if (_secret != null)
buf.append("\n\tSecret : \"").append(_secret).append('"'); buf.append("\n\tSecret : \"").append(_secret).append('"');
buf.append("\n\tAuth Type : "); buf.append("\n\tAuth Type : ");
if (_authType >= 0) if (_authType > 0)
buf.append(_authType); buf.append(_authType);
else else
buf.append("none"); buf.append("none");