Search in sources :

Example 1 with AttachmentUploadAttributes

use of org.whispersystems.signalservice.internal.push.AttachmentUploadAttributes in project libsignal-service-java by signalapp.

the class SignalServiceMessageSender method uploadAttachment.

public SignalServiceAttachmentPointer uploadAttachment(SignalServiceAttachmentStream attachment) throws IOException {
    byte[] attachmentKey = Util.getSecretBytes(64);
    long paddedLength = PaddingInputStream.getPaddedSize(attachment.getLength());
    InputStream dataStream = new PaddingInputStream(attachment.getInputStream(), attachment.getLength());
    long ciphertextLength = AttachmentCipherOutputStream.getCiphertextLength(paddedLength);
    PushAttachmentData attachmentData = new PushAttachmentData(attachment.getContentType(), dataStream, ciphertextLength, new AttachmentCipherOutputStreamFactory(attachmentKey), attachment.getListener());
    AttachmentUploadAttributes uploadAttributes = null;
    if (pipe.get().isPresent()) {
        Log.d(TAG, "Using pipe to retrieve attachment upload attributes...");
        try {
            uploadAttributes = pipe.get().get().getAttachmentUploadAttributes();
        } catch (IOException e) {
            Log.w(TAG, "Failed to retrieve attachment upload attributes using pipe. Falling back...");
        }
    }
    if (uploadAttributes == null) {
        Log.d(TAG, "Not using pipe to retrieve attachment upload attributes...");
        uploadAttributes = socket.getAttachmentUploadAttributes();
    }
    Pair<Long, byte[]> attachmentIdAndDigest = socket.uploadAttachment(attachmentData, uploadAttributes);
    return new SignalServiceAttachmentPointer(attachmentIdAndDigest.first(), attachment.getContentType(), attachmentKey, Optional.of(Util.toIntExact(attachment.getLength())), attachment.getPreview(), attachment.getWidth(), attachment.getHeight(), Optional.of(attachmentIdAndDigest.second()), attachment.getFileName(), attachment.getVoiceNote(), attachment.getCaption(), attachment.getBlurHash());
}
Also used : PaddingInputStream(org.whispersystems.signalservice.internal.crypto.PaddingInputStream) InputStream(java.io.InputStream) PaddingInputStream(org.whispersystems.signalservice.internal.crypto.PaddingInputStream) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) IOException(java.io.IOException) AttachmentUploadAttributes(org.whispersystems.signalservice.internal.push.AttachmentUploadAttributes) PushAttachmentData(org.whispersystems.signalservice.internal.push.PushAttachmentData) AttachmentCipherOutputStreamFactory(org.whispersystems.signalservice.internal.push.http.AttachmentCipherOutputStreamFactory)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 SignalServiceAttachmentPointer (org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer)1 PaddingInputStream (org.whispersystems.signalservice.internal.crypto.PaddingInputStream)1 AttachmentUploadAttributes (org.whispersystems.signalservice.internal.push.AttachmentUploadAttributes)1 PushAttachmentData (org.whispersystems.signalservice.internal.push.PushAttachmentData)1 AttachmentCipherOutputStreamFactory (org.whispersystems.signalservice.internal.push.http.AttachmentCipherOutputStreamFactory)1