Search in sources :

Example 6 with KeyException

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;
    }
}
Also used : PoPToken(com.github.dedis.popstellar.model.objects.security.PoPToken) Lao(com.github.dedis.popstellar.model.objects.Lao) KeyException(com.github.dedis.popstellar.utility.error.keys.KeyException)

Example 7 with KeyException

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();
}
Also used : PoPToken(com.github.dedis.popstellar.model.objects.security.PoPToken) Bitmap(android.graphics.Bitmap) RollCall(com.github.dedis.popstellar.model.objects.RollCall) KeyException(com.github.dedis.popstellar.utility.error.keys.KeyException) Nullable(androidx.annotation.Nullable)

Aggregations

KeyException (com.github.dedis.popstellar.utility.error.keys.KeyException)7 Lao (com.github.dedis.popstellar.model.objects.Lao)6 PoPToken (com.github.dedis.popstellar.model.objects.security.PoPToken)6 Channel (com.github.dedis.popstellar.model.objects.Channel)5 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)4 Disposable (io.reactivex.disposables.Disposable)4 RollCall (com.github.dedis.popstellar.model.objects.RollCall)3 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)2 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)2 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)2 CloseRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall)2 CreateRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)2 OpenRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall)2 Bitmap (android.graphics.Bitmap)1 Nullable (androidx.annotation.Nullable)1 CastVote (com.github.dedis.popstellar.model.network.method.message.data.election.CastVote)1 AddChirp (com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp)1 DeleteChirp (com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp)1 Election (com.github.dedis.popstellar.model.objects.Election)1 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)1