org.whispersystems.signalservice.api.crypto.AttachmentCipherInputStream Java Examples

The following examples show how to use org.whispersystems.signalservice.api.crypto.AttachmentCipherInputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignalServiceMessageReceiver.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Retrieves a {@link SignalServiceStickerManifest}.
 *
 * @param packId The 16-byte packId that identifies the sticker pack.
 * @param packKey The 32-byte packKey that decrypts the sticker pack.
 * @return The {@link SignalServiceStickerManifest} representing the sticker pack.
 * @throws IOException
 * @throws InvalidMessageException
 */
public SignalServiceStickerManifest retrieveStickerManifest(byte[] packId, byte[] packKey)
    throws IOException, InvalidMessageException
{
  byte[] manifestBytes = socket.retrieveStickerManifest(packId);

  InputStream           cipherStream = AttachmentCipherInputStream.createForStickerData(manifestBytes, packKey);
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

  Util.copy(cipherStream, outputStream);

  StickerProtos.Pack                             pack     = StickerProtos.Pack.parseFrom(outputStream.toByteArray());
  List<SignalServiceStickerManifest.StickerInfo> stickers = new ArrayList<>(pack.getStickersCount());
  SignalServiceStickerManifest.StickerInfo       cover    = pack.hasCover() ? new SignalServiceStickerManifest.StickerInfo(pack.getCover().getId(), pack.getCover().getEmoji())
                                                                        : null;

  for (StickerProtos.Pack.Sticker sticker : pack.getStickersList()) {
    stickers.add(new SignalServiceStickerManifest.StickerInfo(sticker.getId(), sticker.getEmoji()));
  }

  return new SignalServiceStickerManifest(pack.getTitle(), pack.getAuthor(), cover, stickers);
}
 
Example #2
Source File: SignalServiceMessageReceiver.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Retrieves a {@link SignalServiceStickerManifest}.
 *
 * @param packId The 16-byte packId that identifies the sticker pack.
 * @param packKey The 32-byte packKey that decrypts the sticker pack.
 * @return The {@link SignalServiceStickerManifest} representing the sticker pack.
 * @throws IOException
 * @throws InvalidMessageException
 */
public SignalServiceStickerManifest retrieveStickerManifest(byte[] packId, byte[] packKey)
    throws IOException, InvalidMessageException
{
  byte[] manifestBytes = socket.retrieveStickerManifest(packId);

  InputStream           cipherStream = AttachmentCipherInputStream.createForStickerData(manifestBytes, packKey);
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

  Util.copy(cipherStream, outputStream);

  StickerProtos.Pack                             pack     = StickerProtos.Pack.parseFrom(outputStream.toByteArray());
  List<SignalServiceStickerManifest.StickerInfo> stickers = new ArrayList<>(pack.getStickersCount());
  SignalServiceStickerManifest.StickerInfo       cover    = pack.hasCover() ? new SignalServiceStickerManifest.StickerInfo(pack.getCover().getId(), pack.getCover().getEmoji())
                                                                        : null;

  for (StickerProtos.Pack.Sticker sticker : pack.getStickersList()) {
    stickers.add(new SignalServiceStickerManifest.StickerInfo(sticker.getId(), sticker.getEmoji()));
  }

  return new SignalServiceStickerManifest(pack.getTitle(), pack.getAuthor(), cover, stickers);
}
 
Example #3
Source File: AttachmentStreamLocalUriFetcher.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void loadData(@NonNull Priority priority, @NonNull DataCallback<? super InputStream> callback) {
  try {
    if (!digest.isPresent()) throw new InvalidMessageException("No attachment digest!");
    is = AttachmentCipherInputStream.createForAttachment(attachment, plaintextLength, key, digest.get());
    callback.onDataReady(is);
  } catch (IOException | InvalidMessageException e) {
    callback.onLoadFailed(e);
  }
}
 
Example #4
Source File: AttachmentStreamLocalUriFetcher.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void loadData(Priority priority, DataCallback<? super InputStream> callback) {
  try {
    if (!digest.isPresent()) throw new InvalidMessageException("No attachment digest!");
    is = AttachmentCipherInputStream.createFor(attachment, plaintextLength, key, digest.get());
    callback.onDataReady(is);
  } catch (IOException | InvalidMessageException e) {
    callback.onLoadFailed(e);
  }
}
 
Example #5
Source File: SignalServiceMessageReceiver.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public InputStream retrieveSticker(byte[] packId, byte[] packKey, int stickerId)
    throws IOException, InvalidMessageException
{
  byte[] data = socket.retrieveSticker(packId, stickerId);
  return AttachmentCipherInputStream.createForStickerData(data, packKey);
}
 
Example #6
Source File: SignalServiceMessageReceiver.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
public InputStream retrieveSticker(byte[] packId, byte[] packKey, int stickerId)
    throws IOException, InvalidMessageException
{
  byte[] data = socket.retrieveSticker(packId, stickerId);
  return AttachmentCipherInputStream.createForStickerData(data, packKey);
}
 
Example #7
Source File: SignalServiceMessageReceiver.java    From mollyim-android with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Retrieves a SignalServiceAttachment.
 *
 * @param pointer The {@link SignalServiceAttachmentPointer}
 *                received in a {@link SignalServiceDataMessage}.
 * @param destination The download destination for this attachment. If this file exists, it is
 *                    assumed that this is previously-downloaded content that can be resumed.
 * @param listener An optional listener (may be null) to receive callbacks on download progress.
 *
 * @return An InputStream that streams the plaintext attachment contents.
 * @throws IOException
 * @throws InvalidMessageException
 */
public InputStream retrieveAttachment(SignalServiceAttachmentPointer pointer, File destination, long maxSizeBytes, ProgressListener listener)
    throws IOException, InvalidMessageException, MissingConfigurationException {
  if (!pointer.getDigest().isPresent()) throw new InvalidMessageException("No attachment digest!");

  socket.retrieveAttachment(pointer.getCdnNumber(), pointer.getRemoteId(), destination, maxSizeBytes, listener);
  return AttachmentCipherInputStream.createForAttachment(destination, pointer.getSize().or(0), pointer.getKey(), pointer.getDigest().get());
}
 
Example #8
Source File: SignalServiceMessageReceiver.java    From libsignal-service-java with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Retrieves a SignalServiceAttachment.
 *
 * @param pointer The {@link SignalServiceAttachmentPointer}
 *                received in a {@link SignalServiceDataMessage}.
 * @param destination The download destination for this attachment.
 * @param listener An optional listener (may be null) to receive callbacks on download progress.
 *
 * @return An InputStream that streams the plaintext attachment contents.
 * @throws IOException
 * @throws InvalidMessageException
 */
public InputStream retrieveAttachment(SignalServiceAttachmentPointer pointer, File destination, int maxSizeBytes, ProgressListener listener)
    throws IOException, InvalidMessageException
{
  if (!pointer.getDigest().isPresent()) throw new InvalidMessageException("No attachment digest!");

  socket.retrieveAttachment(pointer.getId(), destination, maxSizeBytes, listener);
  return AttachmentCipherInputStream.createForAttachment(destination, pointer.getSize().or(0), pointer.getKey(), pointer.getDigest().get());
}