Package com.google.nigori.common

Examples of com.google.nigori.common.Index


      if (args.length != 7) {
        System.err.println("*** Error: exactly seven elements needed for a put action");
        usage();
        return;
      }
      RevValue success = nigori.put(new Index(args[5]), MessageLibrary.toBytes(args[6]));
      System.out.println("Success: " + success);
    } else if (action.equals("get")) {
      if (args.length != 6) {
        System.err.println("*** Error: exactly six elements needed for a get action");
        usage();
        return;
      }
      try {
        Collection<RevValue> data = nigori.get(new Index(args[5]));
        if (data != null) {
          for (RevValue datum : data) {
            System.out.println(datum.getRevision() + " : " + new String(datum.getValue()));
          }
        } else {
          System.out.println("No values for index.");
        }
      } catch (IOException ioe) {
        System.out.println(ioe.getMessage());
      }
    } else if (action.equals("delete")) {
      if (args.length != 6) {
        System.err.println("*** Error: exactly six elements needed for a delete action");
        usage();
        return;
      }
      boolean success = nigori.removeIndex(new Index(args[5]), Revision.EMPTY);
      System.out.println("Success: " + success);
    } else {
      System.err.println("*** Error: Unknown action " + action);
      usage();
    }
View Full Code Here


      UnauthorisedException {

    MigoriDatastore store;
    Thread secondUser;
    // This is the index in the store which is used to hold the shared data
    final Index sharedIndex = new Index(new byte[] {1});
    {
      // This auto-generates a unique username and password used in the store.
      // The username and password is the data which should be shared between two devices.
      final CryptoNigoriDatastore sharedStore = new CryptoNigoriDatastore(HOST, PORT, "nigori");
      final String username = sharedStore.getUsername();
View Full Code Here

        return null;
      }
      List<ByteString> indices = getResponse.getIndicesList();
      List<Index> answer = new ArrayList<Index>(indices.size());
      for (ByteString index : indices) {
        answer.add(new Index(keyManager.decrypt(index.toByteArray())));
      }
      return answer;
    } catch (NotFoundException e) {
      return null;
    }
View Full Code Here

      try {
        assertTrue("Not registered" + i, nigori.register());
        assertTrue("Not a clean store " + i, nigori.getIndices().isEmpty());

        for (IndexValue iv : testCases) {// once round for each
          final Index index = iv.index;
          final Revision revision = iv.revvalue.getRevision();
          final byte[] value = iv.revvalue.getValue();

          assertTrue("Not put " + i, nigori.put(index, revision, value));
          List<RevValue> revs = nigori.get(index);
          assertFalse("Revisions must exist" + i, revs.isEmpty());
          assertThat(revs, hasItem(iv.revvalue));
          assertEquals("Not one revision " + i, 1, revs.size());
          assertTrue("Not deleted" + i, nigori.delete(index, NULL_DELETE_TOKEN));
          assertNull("Not deleted" + i, nigori.get(index));
          assertFalse("Could redelete", nigori.delete(index, NULL_DELETE_TOKEN));
        }
        // allow them to accumulate
        for (IndexValue iv : testCases) {
          final Index index = iv.index;
          final byte[] value = iv.revvalue.getValue();
          final Revision revision = iv.revvalue.getRevision();
          assertTrue("Not put" + i, nigori.put(index, revision, value));
        }
        try {
          for (IndexValue iv : testCases) {
            final Index index = iv.index;
            final byte[] value = iv.revvalue.getValue();
            final Revision revision = iv.revvalue.getRevision();
            assertArrayEquals("Got different" + i, value, nigori.getRevision(index, revision));
          }
        } finally {
          for (IndexValue iv : testCases) {
            final Index index = iv.index;
            if (!iv.later) {
              assertTrue("Not deleted" + i, nigori.delete(index, NULL_DELETE_TOKEN));
            } else {// should have already been deleted
              assertFalse("Not deleted" + i, nigori.delete(index, NULL_DELETE_TOKEN));
            }
          }
        }
        for (IndexValue iv : testCases) {
          final Index index = iv.index;
          assertNull("Still there after deletion " + i, nigori.get(index));
        }
      } finally {
        assertTrue("Not unregistered", nigori.unregister());
      }
View Full Code Here

  @Test
  public void getRevisions() throws IOException, NigoriCryptographyException, UnauthorisedException {
    NigoriDatastore nigori = getStore();
    try {
      assertTrue("Not registered", nigori.register());
      final Index index = new Index("index");
      final Revision a = new Revision("a");
      final Revision b = new Revision("b");
      assertTrue("Not put", nigori.put(index, a, toBytes("aa")));
      assertTrue("Not put", nigori.put(index, b, toBytes("bb")));
      try {
View Full Code Here

  @Test
  public void getIndices() throws IOException, NigoriCryptographyException, UnauthorisedException {
    NigoriDatastore nigori = getStore();
    try {
      assertTrue("Not registered", nigori.register());
      final Index indexa = new Index("indexa");
      final Index indexb = new Index("indexb");
      final Revision revision = new Revision("a");
      assertTrue("Not put", nigori.put(indexa, revision, toBytes("aa")));
      assertTrue("Not put", nigori.put(indexb, revision, toBytes("bb")));
      try {
        List<Index> indices = nigori.getIndices();
View Full Code Here

  public void immutableRevisions() throws IOException, NigoriCryptographyException,
      UnauthorisedException {
    NigoriDatastore nigori = getStore();
    try {
      assertTrue("Not registered", nigori.register());
      final Index index = new Index("index");
      final Revision revision = new Revision("rev");
      assertTrue("Not put", nigori.put(index, revision, Util.int2bin(0)));
      assertFalse("Could replace revision value", nigori.put(index, revision, Util.int2bin(1)));
      nigori.delete(index, NULL_DELETE_TOKEN);
    } finally {
View Full Code Here

    public final Index index;
    public final RevValue revvalue;
    public final boolean later;

    public IndexValue(String index, String revision, String value, boolean later) {
      this.index = new Index(index);
      this.revvalue = new RevValue(toBytes(revision), toBytes(value));
      this.later = later;
    }
View Full Code Here

            for (int i = 0; i < AcceptanceTests.REPEAT * REPEAT_FACTOR; ++i) {
              // check we can do this more than once
              assertTrue("Not registered" + i, nigori.register());
              try {
                for (IndexValue iv : SetGetDeleteTest.testCases) {// once round for each
                  final Index index = iv.index;
                  final byte[] value = iv.revvalue.getValue();
                  final Revision revision = iv.revvalue.getRevision();
                  assertTrue("Not put" + i, nigori.put(index, revision, value));
                  assertArrayEquals("Got different" + i, value, nigori.getRevision(index, revision));
                  assertTrue("Not deleted " + i, nigori.delete(index, NULL_DELETE_TOKEN));
View Full Code Here

            try {
              Random r = new Random();
              for (int i = 0; i < AcceptanceTests.REPEAT * REPEAT_FACTOR; ++i) {
                // check we can do this more than once
                for (IndexValue iv : SetGetDeleteTest.testCases) {// once round for each
                  final Index index = new Index(new byte[16]);
                  r.nextBytes(index.getBytes());// need to generate some different indices
                  final byte[] value = iv.revvalue.getValue();
                  final Revision revision = iv.revvalue.getRevision();
                  assertTrue("Not put" + i, nigori.put(index, revision, value));
                  try {
                    assertArrayEquals("Got different" + i, value, nigori.getRevision(index,
View Full Code Here

TOP

Related Classes of com.google.nigori.common.Index

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.