1package im.conversations.android.xmpp.model.axolotl;
2
3import im.conversations.android.xmpp.model.ByteContent;
4import org.whispersystems.libsignal.InvalidKeyException;
5import org.whispersystems.libsignal.ecc.Curve;
6import org.whispersystems.libsignal.ecc.ECPublicKey;
7
8public interface ECPublicKeyContent extends ByteContent {
9
10 default ECPublicKey asECPublicKey() {
11 try {
12 return Curve.decodePoint(asBytes(), 0);
13 } catch (InvalidKeyException e) {
14 throw new IllegalStateException(
15 String.format("%s does not contain a valid ECPublicKey", getClass().getName()),
16 e);
17 }
18 }
19
20 default void setContent(final ECPublicKey ecPublicKey) {
21 setContent(ecPublicKey.serialize());
22 }
23}