Ejemplo n.º 1
0
        private async Task <AttachmentPointer> CreateAttachmentPointer(CancellationToken token, SignalServiceAttachmentStream attachment)
        {
            byte[]             attachmentKey    = Util.GetSecretBytes(64);
            long               paddedLength     = PaddingInputStream.GetPaddedSize(attachment.Length);
            long               ciphertextLength = AttachmentCipherInputStream.GetCiphertextLength(paddedLength);
            PushAttachmentData attachmentData   = new PushAttachmentData(attachment.ContentType,
                                                                         new PaddingInputStream(attachment.InputStream, attachment.Length),
                                                                         ciphertextLength,
                                                                         new AttachmentCipherOutputStreamFactory(attachmentKey),
                                                                         attachment.Listener);

            (ulong id, byte[] digest) = await socket.SendAttachment(token, attachmentData);

            var attachmentPointer = new AttachmentPointer
            {
                ContentType = attachment.ContentType,
                Id          = id,
                Key         = ByteString.CopyFrom(attachmentKey),
                Digest      = ByteString.CopyFrom(digest),
                Size        = (uint)attachment.Length
            };

            if (attachment.FileName != null)
            {
                attachmentPointer.FileName = attachment.FileName;
            }

            if (attachment.Preview != null)
            {
                attachmentPointer.Thumbnail = ByteString.CopyFrom(attachment.Preview);
            }

            if (attachment.Width > 0)
            {
                attachmentPointer.Width = (uint)attachment.Width;
            }

            if (attachment.Height > 0)
            {
                attachmentPointer.Height = (uint)attachment.Height;
            }

            if (attachment.VoiceNote)
            {
                attachmentPointer.Flags = (uint)AttachmentPointer.Types.Flags.VoiceMessage;
            }

            return(attachmentPointer);
        }
Ejemplo n.º 2
0
        private async Task <AttachmentPointer> createAttachmentPointer(SignalServiceAttachmentStream attachment)
        {
            byte[]             attachmentKey  = Util.getSecretBytes(64);
            PushAttachmentData attachmentData = new PushAttachmentData(attachment.getContentType(),
                                                                       attachment.getInputStream().AsInputStream(),
                                                                       (ulong)attachment.getLength(),
                                                                       attachmentKey);

            ulong attachmentId = await socket.sendAttachment(attachmentData);

            var builder = AttachmentPointer.CreateBuilder()
                          .SetContentType(attachment.getContentType())
                          .SetId(attachmentId)
                          .SetKey(ByteString.CopyFrom(attachmentKey))
                          .SetSize((uint)attachment.getLength());

            if (attachment.getPreview().HasValue)
            {
                builder.SetThumbnail(ByteString.CopyFrom(attachment.getPreview().ForceGetValue()));
            }

            return(builder.Build());
        }
Ejemplo n.º 3
0
        private AttachmentPointer createAttachmentPointer(SignalServiceAttachmentStream attachment)
        {
            byte[]             attachmentKey  = Util.getSecretBytes(64);
            PushAttachmentData attachmentData = new PushAttachmentData(attachment.getContentType(),
                                                                       attachment.getInputStream(),
                                                                       (ulong)attachment.getLength(),
                                                                       attachmentKey);

            Tuple <ulong, byte[]> attachmentIdAndDigest = socket.SendAttachment(attachmentData);

            var attachmentPointer = new AttachmentPointer
            {
                ContentType = attachment.getContentType(),
                Id          = attachmentIdAndDigest.Item1,
                Key         = ByteString.CopyFrom(attachmentKey),
                Digest      = ByteString.CopyFrom(attachmentIdAndDigest.Item2),
                Size        = (uint)attachment.getLength()
            };

            if (attachment.FileName != null)
            {
                attachmentPointer.FileName = attachment.FileName;
            }

            if (attachment.getPreview().HasValue)
            {
                attachmentPointer.Thumbnail = ByteString.CopyFrom(attachment.getPreview().ForceGetValue());
            }

            if (attachment.VoiceNote)
            {
                attachmentPointer.Flags = (uint)AttachmentPointer.Types.Flags.VoiceMessage;
            }

            return(attachmentPointer);
        }