use of com.github.dedis.popstellar.utility.error.keys.KeyException in project popstellar by dedis.
the class SocialMediaViewModel method isOwner.
/**
* Check whether the sender of a chirp is the current user
*
* @param sender String of the PoPToken PublicKey
* @return true if the sender is the current user
*/
public boolean isOwner(String sender) {
Log.d(TAG, "Testing if the sender is also the owner");
Lao lao = getCurrentLao();
if (lao == null) {
Log.e(TAG, LAO_FAILURE_MESSAGE);
return false;
}
try {
PoPToken token = keyManager.getValidPoPToken(lao);
return sender.equals(token.getPublicKey().getEncoded());
} catch (KeyException e) {
ErrorUtils.logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token);
return false;
}
}
use of com.github.dedis.popstellar.utility.error.keys.KeyException in project popstellar by dedis.
the class RollCallTokenFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mRollCallTokenFragmentBinding = RollCallTokenFragmentBinding.inflate(inflater, container, false);
mLaoDetailViewModel = LaoDetailActivity.obtainViewModel(requireActivity());
String rollCallId = requireArguments().getString(EXTRA_ID);
Optional<RollCall> optRollCall = mLaoDetailViewModel.getCurrentLao().getValue().getRollCall(rollCallId);
if (!optRollCall.isPresent()) {
Log.d(TAG, "failed to retrieve roll call with id " + rollCallId);
mLaoDetailViewModel.openLaoWallet();
} else {
rollCall = optRollCall.get();
}
String firstLaoId = mLaoDetailViewModel.getCurrentLaoValue().getId();
String pk = "";
Log.d(TAG, "rollcall: " + rollCallId);
try {
PoPToken token = wallet.generatePoPToken(firstLaoId, rollCall.getPersistentId());
pk = token.getPublicKey().getEncoded();
} catch (KeyException e) {
Log.d(TAG, "failed to retrieve token from wallet", e);
mLaoDetailViewModel.openLaoWallet();
}
mRollCallTokenFragmentBinding.rollcallName.setText("Roll Call: " + rollCall.getName());
mRollCallTokenFragmentBinding.publicKey.setText("Public key:\n" + pk);
Bitmap myBitmap = QRCode.from(pk).bitmap();
mRollCallTokenFragmentBinding.pkQrCode.setImageBitmap(myBitmap);
mRollCallTokenFragmentBinding.setLifecycleOwner(getActivity());
return mRollCallTokenFragmentBinding.getRoot();
}
Aggregations