use of im.actor.runtime.bser.BserWriter in project actor-platform by actorapp.
the class AbsContentContainer method buildContainer.
public byte[] buildContainer() throws IOException {
DataOutput res = new DataOutput();
BserWriter writer = new BserWriter(res);
if (this instanceof ContentLocalContainer) {
writer.writeInt(1, TYPE_LOCAL);
writer.writeBytes(2, ((ContentLocalContainer) this).getContent().buildContainer());
} else if (this instanceof ContentRemoteContainer) {
writer.writeInt(1, TYPE_REMOTE);
writer.writeBytes(2, ((ContentRemoteContainer) this).getMessage().buildContainer());
} else {
throw new IOException("Unknown type");
}
return res.toByteArray();
}
use of im.actor.runtime.bser.BserWriter in project actor-platform by actorapp.
the class RatchetKeySignature method hashForSignature.
public static byte[] hashForSignature(long keyId, String keyAlg, byte[] publicKey) {
byte[] toSign;
try {
DataOutput dataOutput = new DataOutput();
BserWriter writer = new BserWriter(dataOutput);
writer.writeLong(1, keyId);
writer.writeString(2, keyAlg);
Digest sha256 = Crypto.createSHA256();
sha256.update(publicKey, 0, publicKey.length);
byte[] hash = new byte[32];
sha256.doFinal(hash, 0);
writer.writeBytes(3, hash);
toSign = dataOutput.toByteArray();
} catch (Exception e) {
// Never happens
return new byte[0];
}
return toSign;
}
use of im.actor.runtime.bser.BserWriter in project actor-platform by actorapp.
the class AbsContent method serialize.
public static byte[] serialize(AbsContent content) throws IOException {
DataOutput dataOutput = new DataOutput();
BserWriter writer = new BserWriter(dataOutput);
// Mark new layout
writer.writeBool(32, true);
// Write content
writer.writeBytes(33, content.getContentContainer().buildContainer());
return dataOutput.toByteArray();
}
use of im.actor.runtime.bser.BserWriter in project actor-platform by actorapp.
the class AbsLocalContent method buildContainer.
public byte[] buildContainer() throws IOException {
DataOutput res = new DataOutput();
BserWriter writer = new BserWriter(res);
if (this instanceof LocalPhoto) {
writer.writeInt(1, CONTENT_PHOTO);
} else if (this instanceof LocalVideo) {
writer.writeInt(1, CONTENT_VIDEO);
} else if (this instanceof LocalDocument) {
writer.writeInt(1, CONTENT_DOC);
} else if (this instanceof LocalVoice) {
writer.writeInt(1, CONTENT_VOICE);
} else if (this instanceof LocalAnimation) {
writer.writeInt(1, CONTENT_ANIMATION);
} else {
throw new IOException("Unknown type");
}
writer.writeBytes(2, toByteArray());
return res.toByteArray();
}
Aggregations