Search in sources :

Example 1 with BserWriter

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();
}
Also used : DataOutput(im.actor.runtime.bser.DataOutput) BserWriter(im.actor.runtime.bser.BserWriter) IOException(java.io.IOException)

Example 2 with BserWriter

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;
}
Also used : DataOutput(im.actor.runtime.bser.DataOutput) Digest(im.actor.runtime.crypto.Digest) BserWriter(im.actor.runtime.bser.BserWriter)

Example 3 with BserWriter

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();
}
Also used : DataOutput(im.actor.runtime.bser.DataOutput) BserWriter(im.actor.runtime.bser.BserWriter)

Example 4 with BserWriter

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();
}
Also used : DataOutput(im.actor.runtime.bser.DataOutput) BserWriter(im.actor.runtime.bser.BserWriter) IOException(java.io.IOException)

Aggregations

BserWriter (im.actor.runtime.bser.BserWriter)4 DataOutput (im.actor.runtime.bser.DataOutput)4 IOException (java.io.IOException)2 Digest (im.actor.runtime.crypto.Digest)1