コード例 #1
0
 public NorvosPreKeyStore() {
   lastResortKey = KeyHelper.generateLastResortPreKey();
   oneTimePreKeys = new CircularBuffer<PreKeyRecord>(Medium.MAX_VALUE);
   Random r = new Random();
   List<PreKeyRecord> list = KeyHelper.generatePreKeys(r.nextInt(Medium.MAX_VALUE), 100);
   for (PreKeyRecord key : list) {
     oneTimePreKeys.add(key.getId(), key);
   }
 }
コード例 #2
0
  public synchronized byte[] serialize() {
    Builder builder = PreKeyStoreStructure.newBuilder();
    for (PreKeyRecord entry : oneTimePreKeys.getAll()) {
      PreKeyStructure struct =
          PreKeyStructure.newBuilder()
              .setKeyId(entry.getId())
              .setPreKeyRecord(ByteString.copyFrom(entry.serialize()))
              .build();
      builder.addOneTimePreKey(struct);
    }

    return builder.build().toByteArray();
  }
コード例 #3
0
 @Override
 public void storePreKey(int preKeyId, PreKeyRecord record) {
   synchronized (FILE_LOCK) {
     try {
       storeSerializedRecord(getPreKeyFile(preKeyId), record.serialize());
     } catch (IOException e) {
       throw new AssertionError(e);
     }
   }
 }
コード例 #4
0
ファイル: PreKeyTable.java プロジェクト: a10b/norvos
  public void storeKey(final int id, final PreKeyRecord preKey) throws SQLException {
    final String query = "MERGE INTO prekeystore VALUES (?, ?)";

    try (PreparedStatement stmt = Database.ensureTableExists(this).prepareStatement(query)) {

      stmt.setInt(1, id);
      stmt.setBytes(2, preKey.serialize());

      stmt.execute();
    }
  }