Exemplo n.º 1
0
  @Override
  public boolean removeMetadataBlob(
      UserPublicKey owner, byte[] encodedWritingPublicKey, byte[] writingKeySignedMapKeyPlusBlob) {
    UserPublicKey writingKey = new UserPublicKey(encodedWritingPublicKey);

    try {
      byte[] payload = writingKey.unsignMessage(writingKeySignedMapKeyPlusBlob);
      byte[] mapKey = Arrays.copyOfRange(payload, 0, 32);
      byte[] metadataBlob =
          Arrays.copyOfRange(
              payload,
              32,
              payload
                  .length); // will be zero length for now // TODO  change to the current blob hash
      MetadataBlob blob = new MetadataBlob(writingKey.getPublicKeys(), mapKey, metadataBlob);
      return blob.delete();
    } catch (TweetNaCl.InvalidSignatureException e) {
      System.err.println(
          "Invalid signature during removeMetadataBlob for owner: "
              + owner
              + " and sharer: "
              + writingKey);
      return false;
    }
  }
Exemplo n.º 2
0
  @Override
  public boolean setMetadataBlob(
      UserPublicKey owner, byte[] encodedWritingPublicKey, byte[] writingKeySignedMapKey) {
    UserPublicKey writingKey = new UserPublicKey(encodedWritingPublicKey);

    try {
      byte[] payload = writingKey.unsignMessage(writingKeySignedMapKey);
      byte[] mapKey = Arrays.copyOfRange(payload, 0, 32);
      byte[] metadataBlob = Arrays.copyOfRange(payload, 32, payload.length);
      MetadataBlob blob = new MetadataBlob(writingKey.getPublicKeys(), mapKey, metadataBlob);
      return blob.insert();
    } catch (TweetNaCl.InvalidSignatureException e) {
      System.err.println(
          "Invalid signature during setMetadataBlob for owner: "
              + owner
              + " and sharer: "
              + writingKey);
      return false;
    }
  }
Exemplo n.º 3
0
 public static <T> T[] subarray(T[] a, int off, int len) {
   return Arrays.copyOfRange(a,off,off+len);
 }