* unifying Android and Desktop SDK * implement desktop SDK adapter * updating declarations * change include syntax * following jitpack.io guide for Android libraries * add install task to all artefacts, add javadoc generation * fixing javadoc * use explicit provider "SC" instead of relying on order * move to BouncyCastle for desktop compatibility * improve documentation
61 lines
1.5 KiB
Java
61 lines
1.5 KiB
Java
package im.status.keycard.applet;
|
|
|
|
import org.bouncycastle.util.encoders.Base64;
|
|
|
|
import java.util.Arrays;
|
|
|
|
/**
|
|
* Stores pairing information.
|
|
*/
|
|
public class Pairing {
|
|
private byte[] pairingKey;
|
|
private byte pairingIndex;
|
|
|
|
/**
|
|
* Constructor. The pairingKey and pairingIndex are those generated at the end of a successful pairing.
|
|
* @param pairingKey the pairing key
|
|
* @param pairingIndex the pairing index
|
|
*/
|
|
public Pairing(byte[] pairingKey, byte pairingIndex) {
|
|
this.pairingKey = pairingKey;
|
|
this.pairingIndex = pairingIndex;
|
|
}
|
|
|
|
/**
|
|
* Constructor. Initializes from a byte array previously generated from the toByteArray method
|
|
* @param fromByteArray the result of a previous toByteArray invocation
|
|
*/
|
|
public Pairing(byte[] fromByteArray) {
|
|
pairingIndex = fromByteArray[0];
|
|
pairingKey = Arrays.copyOfRange(fromByteArray, 1, fromByteArray.length);
|
|
}
|
|
|
|
/**
|
|
* Constructor. Initializes from a String previously generated from the toBase64 method
|
|
* @param base64 the result of a previous toBase64 invocation
|
|
*/
|
|
public Pairing(String base64) {
|
|
this(Base64.decode(base64));
|
|
}
|
|
|
|
public byte[] getPairingKey() {
|
|
return pairingKey;
|
|
}
|
|
|
|
public byte getPairingIndex() {
|
|
return pairingIndex;
|
|
}
|
|
|
|
public byte[] toByteArray() {
|
|
byte[] res = new byte[pairingKey.length + 1];
|
|
res[0] = pairingIndex;
|
|
System.arraycopy(pairingKey, 0, res, 1, pairingKey.length);
|
|
|
|
return res;
|
|
}
|
|
|
|
public String toBase64() {
|
|
return Base64.toBase64String(toByteArray());
|
|
}
|
|
}
|