DataStore implements DataCacheProvider, RolesProvider { byte[] toIntegerBytes(final BigInteger bigInt, boolean rfc) { if (!rfc) { return bigInt.toByteArray(); } int bitlen = bigInt.bitLength(); bitlen = ((bitlen + 7) >> 3) << 3; final byte[] bigBytes = bigInt.toByteArray(); if (((bigInt.bitLength() % 8) != 0) && (((bigInt.bitLength() / 8) + 1) == (bitlen / 8))) { return bigBytes; } int startSrc = 0; int len = bigBytes.length; if ((bigInt.bitLength() % 8) == 0) { startSrc = 1; len--; } final int startDst = bitlen / 8 - len; final byte[] resizedBytes = new byte[bitlen / 8]; System.arraycopy(bigBytes, startSrc, resizedBytes, startDst, len); return resizedBytes; } DataStore(ChangeLogStore clogStore, CloudStore cloudStore); JWKList getZtsJWKList(Boolean rfc); void init(); boolean processDomain(SignedDomain signedDomain, boolean saveInStore); boolean processDomainDeletes(); void processDomainChecks(); boolean processDomainUpdates(); DomainData getDomainData(String name); void addDomainToCache(String name, DataCache dataCache); @Override DataCache getDataCache(String domainName); List<GroupMember> getGroupMembers(final String groupName); void getAccessibleRoles(DataCache data, String domainName, String identity,
            String[] requestedRoleList, Set<String> accessibleRoles, boolean keepFullName); String getPublicKey(String domain, String service, String keyId); HostServices getHostServices(String host); CloudStore getCloudStore(); void setCloudStore(CloudStore cloudStore); Cache<String, DataCache> getCacheStore(); Map<String, String> getPublicKeyCache(); @Override List<Role> getRolesByDomain(String domain);  }
@Test public void testToIntegerBytes1() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); final Base64.Encoder encoder = Base64.getEncoder(); final String encodedInt1 = "li7dzDacuo67Jg7mtqEm2TRuOMU="; final BigInteger bigInt1 = new BigInteger("85739377120809420210425962799" + "0318636601332086981"); assertEquals(encodedInt1, new String(encoder.encode(store.toIntegerBytes(bigInt1, true)))); }
@Test public void testToIntegerBytes2() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); final Base64.Encoder encoder = Base64.getEncoder(); final String encodedInt2 = "9B5ypLY9pMOmtxCeTDHgwdNFeGs="; final BigInteger bigInt2 = new BigInteger("13936727572861167254666467268" + "91466679477132949611"); assertEquals(encodedInt2, new String(encoder.encode(store.toIntegerBytes(bigInt2, true)))); }
@Test public void testToIntegerBytes3() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); final Base64.Encoder encoder = Base64.getEncoder(); final String encodedInt3 = "FKIhdgaG5LGKiEtF1vHy4f3y700zaD6QwDS3IrNVGzNp2" + "rY+1LFWTK6D44AyiC1n8uWz1itkYMZF0/aKDK0Yjg=="; final BigInteger bigInt3 = new BigInteger( "10806548154093873461951748545" + "1196989136416448805819079363524309897749044958112417136240557" + "4495062430572478766856090958495998158114332651671116876320938126"); assertEquals(encodedInt3, new String(encoder.encode(store.toIntegerBytes(bigInt3, true)))); }
@Test public void testToIntegerBytes4() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); final Base64.Encoder encoder = Base64.getEncoder(); final String encodedInt4 = "ctA8YGxrtngg/zKVvqEOefnwmViFztcnPBYPlJsvh6yKI" + "4iDm68fnp4Mi3RrJ6bZAygFrUIQLxLjV+OJtgJAEto0xAs+Mehuq1DkSFEpP3o" + "DzCTOsrOiS1DwQe4oIb7zVk/9l7aPtJMHW0LVlMdwZNFNNJoqMcT2ZfCPrfvYv" + "Q0="; final BigInteger bigInt4 = new BigInteger( "80624726256040348115552042320" + "6968135001872753709424419772586693950232350200555646471175944" + "519297087885987040810778908507262272892702303774422853675597" + "748008534040890923814202286633163248086055216976551456088015" + "338880713818192088877057717530169381044092839402438015097654" + "53542091716518238707344493641683483917"); assertEquals(encodedInt4, new String(encoder.encode(store.toIntegerBytes(bigInt4, true)))); }