示例#1
0
  private static int getNextSignedPreKeyId(Context context) {
    try {
      File nextFile = new File(getSignedPreKeysDirectory(context), SignedPreKeyIndex.FILE_NAME);

      if (!nextFile.exists()) {
        return Util.getSecureRandom().nextInt(Medium.MAX_VALUE);
      } else {
        InputStreamReader reader = new InputStreamReader(new FileInputStream(nextFile));
        SignedPreKeyIndex index = JsonUtils.fromJson(reader, SignedPreKeyIndex.class);
        reader.close();
        return index.nextSignedPreKeyId;
      }
    } catch (IOException e) {
      Log.w("PreKeyUtil", e);
      return Util.getSecureRandom().nextInt(Medium.MAX_VALUE);
    }
  }
  private Set<String> getE164Numbers(Set<Recipient> recipients) throws InvalidNumberException {
    Set<String> results = new HashSet<String>();

    for (Recipient recipient : recipients) {
      results.add(Util.canonicalizeNumber(this, recipient.getNumber()));
    }

    return results;
  }
  private TextSecureAttachmentPointer createAttachmentPointer(
      MasterSecret masterSecret, PduPart part) throws InvalidPartException {
    try {
      MasterCipher masterCipher = new MasterCipher(masterSecret);
      long id = Long.parseLong(Util.toIsoString(part.getContentLocation()));
      byte[] key =
          masterCipher.decryptBytes(Base64.decode(Util.toIsoString(part.getContentDisposition())));
      String relay = null;

      if (part.getName() != null) {
        relay = Util.toIsoString(part.getName());
      }

      return new TextSecureAttachmentPointer(id, null, key, relay);
    } catch (InvalidMessageException | IOException e) {
      Log.w(TAG, e);
      throw new InvalidPartException(e);
    }
  }
 private static boolean isActiveInDirectory(Context context, Recipient recipient) {
   try {
     if (!TextSecureDirectory.getInstance(context)
         .isActiveNumber(Util.canonicalizeNumber(context, recipient.getNumber()))) {
       return false;
     }
   } catch (NotInDirectoryException e) {
     return false;
   } catch (InvalidNumberException e) {
     return false;
   }
   return true;
 }