use of co.krypt.krypton.pgp.PGPException in project krypton-android by kryptco.
the class MeStorage method loadWithUserID.
public Profile loadWithUserID(@Nullable UserID userID) {
synchronized (lock) {
String meJSON = preferences.getString("ME", null);
if (meJSON == null) {
Log.i(TAG, "no profile found");
return null;
}
Profile me = JSON.fromJson(meJSON, Profile.class);
if (me == null) {
Log.i(TAG, "no profile found");
return null;
}
try {
SSHKeyPairI kp = getOrLoadKeyPair(context);
if (kp != null) {
me.sshWirePublicKey = kp.publicKeySSHWireFormat();
if (userID != null) {
try {
List<UserID> userIDs = getUserIDs();
// keep USER_ID_LIMIT most recent UserIDs
if (userIDs.remove(userID)) {
userIDs.add(userID);
} else {
if (userIDs.size() >= USER_ID_LIMIT) {
userIDs.remove(0);
}
userIDs.add(userID);
PGPPublicKey pgpPublicKey = PGPManager.publicKeyWithIdentities(kp, userIDs);
me.pgpPublicKey = pgpPublicKey.serializedBytes();
if (userIDs.size() == USER_ID_LIMIT) {
// detect abuse of exporting PGP userIDs
Notifications.notifyPGPKeyExport(context, pgpPublicKey);
}
}
set(me, userIDs);
} catch (PGPException | IOException e) {
e.printStackTrace();
}
}
}
} catch (InvalidKeyException | IOException | CryptoException e) {
e.printStackTrace();
}
try {
me.teamCheckpoint = TeamDataProvider.getTeamCheckpoint(context).success;
} catch (Native.NotLinked notLinked) {
notLinked.printStackTrace();
}
return me;
}
}
Aggregations