예제 #1
0
파일: SM.java 프로젝트: mehrvarz/P2pChatOTR
  /**
   * Takes a byte array containing serialized and concatenated MPIs and converts it to an array of
   * MPIs. The buffer is assumed to consist of a 4-byte int containing the number of MPIs in the
   * array, followed by {size, data} pairs for each MPI.
   *
   * @throws OTRException
   */
  public static MPI[] unserializeMPIArray(byte[] buffer) throws OTRException {
    InBuf ibuf = new InBuf(buffer);

    int count = (int) ibuf.readUInt();

    if (count <= 0) throw new OTRException("Invalid count");

    MPI[] mpis = new MPI[count];

    for (int i = 0; i < count; i++) {
      mpis[i] = MPI.readMPI(ibuf);
    }

    return mpis;
  }