/** * Serialize key to the {@link Binder}. Due to the multiplatform nature of attesta items, especially keys that are * often part of the {@link Capsule}, it is not possible to use default java serialization mechanics. Instead, we * serialize objects to Binders that can be effectively transmitted over the network and reconstructed on the any * platform. * <p> * Note that derived classes usually do not override it, instead, they should properly initialize {@link #keyInfo} * and provide {@link #pack()} and {@link #unpack(byte[])} methods, that are widely used across the system. for that * reason we make this method final as for now. If you think you know the case when it is necessary to override it, * contact developers. * <p> * See {@link #fromBinder(Binder)} for deserialization. * * @return binder with packed key. */ @Override public final Binder toBinder() { return new Binder("keyInfo", packedInfo(), "data", pack() ); }
public String packToBase64String() { return Base64.encodeString(pack()); }
@NonNull private HashMap<String, AbstractKey> prepareSigners(Binder payload) { HashMap<String, AbstractKey> sigIds = new HashMap<>(); if (signers != null && !signers.isEmpty()) { ArrayList<Binder> s = payload.set("signers", new ArrayList<>()); int i = 0; for (Binder b : signers.values()) { final String id = b.getStringOrThrow("id"); final AbstractKey key = (AbstractKey) b.get("key"); sigIds.put(id, key); Binder signerData = new Binder( "id", id, "key", key.getPublicKey().pack(), "data", b.getBinder("data") ); s.add(signerData); } } return sigIds; }