use of com.github.dedis.popstellar.model.objects.security.PublicKey in project popstellar by dedis.
the class LaoHandler method updateLaoWitnessesWitnessMessage.
public static WitnessMessage updateLaoWitnessesWitnessMessage(MessageID messageId, UpdateLao updateLao, Lao lao) {
WitnessMessage message = new WitnessMessage(messageId);
List<PublicKey> tempList = new ArrayList<>(updateLao.getWitnesses());
message.setTitle("Update Lao Witnesses");
message.setDescription("Lao Name : " + lao.getName() + "\n" + "Message ID : " + messageId + "\n" + "New Witness ID : " + tempList.get(tempList.size() - 1));
return message;
}
use of com.github.dedis.popstellar.model.objects.security.PublicKey in project popstellar by dedis.
the class KeyManager method getKeyPair.
@VisibleForTesting
public KeyPair getKeyPair(KeysetHandle keysetHandle) throws GeneralSecurityException, IOException {
PrivateKey privateKey = new ProtectedPrivateKey(keysetHandle);
PublicKey publicKey = getPublicKey(keysetHandle);
return new KeyPair(privateKey, publicKey);
}
use of com.github.dedis.popstellar.model.objects.security.PublicKey in project popstellar by dedis.
the class ElectInstanceTest method acceptorsResponsesTest.
@Test
public void acceptorsResponsesTest() {
MessageID messageId1 = generateMessageID();
MessageID messageId2 = generateMessageID();
String instanceId = electInstance.getInstanceId();
ConsensusElectAccept electAccept = new ConsensusElectAccept(instanceId, electMessageId, true);
ConsensusElectAccept electReject = new ConsensusElectAccept(instanceId, electMessageId, false);
electInstance.addElectAccept(node2, messageId1, electAccept);
electInstance.addElectAccept(node2, messageId2, electReject);
Map<PublicKey, MessageID> messageIds = electInstance.getAcceptorsToMessageId();
assertEquals(1, messageIds.size());
assertEquals(messageId1, messageIds.get(node2));
}
use of com.github.dedis.popstellar.model.objects.security.PublicKey in project popstellar by dedis.
the class ChirpListAdapter method getView.
@Override
public View getView(int position, View chirpView, ViewGroup viewGroup) {
if (chirpView == null) {
chirpView = layoutInflater.inflate(R.layout.chirp_card, null);
}
Chirp chirp = getItem(position);
if (chirp == null) {
throw new IllegalArgumentException("The chirp does not exist");
}
PublicKey publicKey = chirp.getSender();
long timestamp = chirp.getTimestamp();
String text;
TextView itemUsername = chirpView.findViewById(R.id.social_media_username);
TextView itemTime = chirpView.findViewById(R.id.social_media_time);
TextView itemText = chirpView.findViewById(R.id.social_media_text);
if (socialMediaViewModel.isOwner(publicKey.getEncoded())) {
ImageButton deleteChirp = chirpView.findViewById(R.id.delete_chirp_button);
deleteChirp.setVisibility(View.VISIBLE);
deleteChirp.setOnClickListener(v -> socialMediaViewModel.deleteChirpEvent(chirp.getId()));
}
if (chirp.getIsDeleted()) {
text = "Chirp is deleted.";
ImageButton deleteChirp = chirpView.findViewById(R.id.delete_chirp_button);
deleteChirp.setVisibility(View.GONE);
itemText.setTextColor(Color.GRAY);
} else {
text = chirp.getText();
}
itemUsername.setText(publicKey.getEncoded());
itemTime.setText(getRelativeTimeSpanString(timestamp * 1000));
itemText.setText(text);
return chirpView;
}
use of com.github.dedis.popstellar.model.objects.security.PublicKey in project popstellar by dedis.
the class ChirpHandler method handleChirpAdd.
/**
* Process an AddChirp message.
*
* @param context the HandlerContext of the message
* @param addChirp the data of the message that was received
*/
public static void handleChirpAdd(HandlerContext context, AddChirp addChirp) {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
MessageID messageId = context.getMessageId();
PublicKey senderPk = context.getSenderPk();
Lao lao = laoRepository.getLaoByChannel(channel);
Chirp chirp = new Chirp(messageId);
chirp.setChannel(channel);
chirp.setSender(senderPk);
chirp.setText(addChirp.getText());
chirp.setTimestamp(addChirp.getTimestamp());
chirp.setParentId(addChirp.getParentId().orElse(new MessageID("")));
lao.updateAllChirps(messageId, chirp);
}
Aggregations