use of com.google.spanner.v1.Session in project xipki by xipki.
the class IaikP11Slot method sign.
byte[] sign(long mechanism, P11Params parameters, byte[] content, IaikP11Identity identity) throws P11TokenException {
ParamUtil.requireNonNull("content", content);
assertMechanismSupported(mechanism);
int len = content.length;
int expectedSignatureLen;
if (mechanism == PKCS11Constants.CKM_SHA_1_HMAC) {
expectedSignatureLen = 20;
} else if (mechanism == PKCS11Constants.CKM_SHA224_HMAC || mechanism == PKCS11Constants.CKM_SHA3_224) {
expectedSignatureLen = 28;
} else if (mechanism == PKCS11Constants.CKM_SHA256_HMAC || mechanism == PKCS11Constants.CKM_SHA3_256) {
expectedSignatureLen = 32;
} else if (mechanism == PKCS11Constants.CKM_SHA384_HMAC || mechanism == PKCS11Constants.CKM_SHA3_384) {
expectedSignatureLen = 48;
} else if (mechanism == PKCS11Constants.CKM_SHA512_HMAC || mechanism == PKCS11Constants.CKM_SHA3_512) {
expectedSignatureLen = 64;
} else if (mechanism == PKCS11Constants.CKM_VENDOR_SM2 || mechanism == PKCS11Constants.CKM_VENDOR_SM2_SM3) {
expectedSignatureLen = 32;
} else {
expectedSignatureLen = identity.getExpectedSignatureLen();
}
ConcurrentBagEntry<Session> session0 = borrowSession();
try {
Session session = session0.value();
if (len <= maxMessageSize) {
return singleSign(session, mechanism, parameters, content, identity);
}
Key signingKey = identity.getSigningKey();
Mechanism mechanismObj = getMechanism(mechanism, parameters);
if (LOG.isTraceEnabled()) {
LOG.debug("sign (init, update, then finish) with private key:\n{}", signingKey);
}
session.signInit(mechanismObj, signingKey);
for (int i = 0; i < len; i += maxMessageSize) {
int blockLen = Math.min(maxMessageSize, len - i);
// byte[] block = new byte[blockLen];
// System.arraycopy(content, i, block, 0, blockLen);
session.signUpdate(content, i, blockLen);
}
return session.signFinal(expectedSignatureLen);
} catch (TokenException ex) {
throw new P11TokenException(ex);
} finally {
sessions.requite(session0);
}
}
use of com.google.spanner.v1.Session in project xipki by xipki.
the class IaikP11Slot method openSession.
private Session openSession(boolean rwSession) throws P11TokenException {
Session session;
try {
session = slot.getToken().openSession(Token.SessionType.SERIAL_SESSION, rwSession, null, null);
} catch (TokenException ex) {
throw new P11TokenException(ex.getMessage(), ex);
}
countSessions.incrementAndGet();
return session;
}
use of com.google.spanner.v1.Session in project rdf2neo by Rothamsted.
the class CypherHandlersIT method testRelations.
/**
* Tests {@link CyRelationLoadingHandler} to see if relations are mapped from RDF and loaded into Neo4J.
*/
@Test
public void testRelations() throws Exception {
try (Driver neoDriver = GraphDatabase.driver("bolt://127.0.0.1:7687", AuthTokens.basic("neo4j", "test"));
CyRelationLoadingHandler handler = new CyRelationLoadingHandler();
RdfDataManager rdfMgr = new RdfDataManager(RdfDataManagerTest.TDB_PATH);
Neo4jDataManager neoMgr = new Neo4jDataManager(neoDriver)) {
handler.setRdfDataManager(rdfMgr);
handler.setNeo4jDataManager(neoMgr);
handler.setRelationTypesSparql(RdfDataManagerTest.SPARQL_REL_TYPES);
handler.setRelationPropsSparql(RdfDataManagerTest.SPARQL_REL_PROPS);
Set<QuerySolution> relSparqlRows = new HashSet<>();
Dataset dataSet = rdfMgr.getDataSet();
Txn.executeRead(dataSet, () -> SparqlUtils.select(RdfDataManagerTest.SPARQL_REL_TYPES, rdfMgr.getDataSet().getDefaultModel()).forEachRemaining(row -> relSparqlRows.add(row)));
handler.accept(relSparqlRows);
Session session = neoDriver.session(AccessMode.READ);
StatementResult cursor = session.run("MATCH ()-[r]->() RETURN COUNT ( r ) AS ct");
Assert.assertEquals("Wrong count for relations", 3, cursor.next().get("ct").asLong());
cursor = session.run("MATCH p = (:TestNode{ iri:$iri1 })-[:relatedTo]->(:TestNode{ iri:$iri2 }) RETURN COUNT ( p ) AS ct", parameters("iri1", iri("ex:1"), "iri2", iri("ex:2")));
Assert.assertEquals("Wrong count for {1 relatedTo 2}!", 1, cursor.next().get("ct").asLong());
cursor = session.run("MATCH p = (:SuperTestNode{ iri:$iri1 })-[:derivedFrom]->(:TestNode{ iri:$iri2 }) RETURN COUNT ( p ) AS ct", parameters("iri1", iri("ex:3"), "iri2", iri("ex:1")));
Assert.assertEquals("Wrong count for {3 derivedFrom 1}!", 1, cursor.next().get("ct").asLong());
cursor = session.run("MATCH (:TestNode{ iri:$iri1 })-[r:relatedTo]->(:AdditionalLabel{ iri:$iri2 }) RETURN r.note AS note", parameters("iri1", iri("ex:2"), "iri2", iri("ex:3")));
assertTrue("{2 relatedTo 3} not found!", cursor.hasNext());
Set<String> values = cursor.next().get("note").asList().stream().map(v -> (String) v).collect(Collectors.toSet());
Set<String> refValues = new HashSet<>(Arrays.asList(new String[] { "Reified Relation", "Another Note" }));
assertTrue("reified relation, wrong property value for 'note'!", Sets.difference(values, refValues).isEmpty());
}
}
use of com.google.spanner.v1.Session in project cypher-for-gremlin by opencypher.
the class GremlinNeo4jDriverTest method translating.
@Test
public void translating() {
Config config = Config.build().withTranslation(TranslatorFlavor.gremlinServer()).toConfig();
Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort(), config);
try (Session session = driver.session()) {
StatementResult result = session.run("MATCH (n:person) RETURN count(n) as count");
int count = result.single().get("count").asInt();
assertThat(count).isEqualTo(4);
}
}
use of com.google.spanner.v1.Session in project cypher-for-gremlin by opencypher.
the class GremlinNeo4jDriverTest method withParameter.
@Test
public void withParameter() {
Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
try (Session session = driver.session()) {
StatementResult result = session.run("CREATE (a:Greeting) " + "SET a.message = $message " + "RETURN a.message", parameters("message", "Hello"));
String message = result.single().get(0).asString();
assertThat(message).isEqualTo("Hello");
}
}
Aggregations