repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
Chicken-Bones/WirelessRedstone
src/codechicken/wirelessredstone/addons/WirelessMapNodeStorage.java
// Path: src/codechicken/wirelessredstone/core/FreqCoord.java // public class FreqCoord implements Comparable<FreqCoord> // { // public FreqCoord(int x, int y, int z, int freq) // { // this.x = x; // this.y = y; // this.z = z; // this.freq = freq; // } // // public FreqCoord(ITileWireless itile) // { // TileEntity tile = (TileEntity)itile; // x = tile.xCoord; // y = tile.yCoord; // z = tile.zCoord; // freq = itile.getFreq(); // } // // public FreqCoord(BlockCoord node, int freq) // { // x = node.x; // y = node.y; // z = node.z; // this.freq = freq; // } // // public int compareTo(FreqCoord node2) // { // if(freq != node2.freq) return freq < node2.freq ? -1 : 1; // if(x != node2.x) return x < node2.x ? -1 : 1; // if(z != node2.z) return z < node2.z ? -1 : 1; // if(y != node2.y) return y < node2.y ? -1 : 1; // return 0; // } // // public String toString() // { // return "["+x+","+y+","+z+" on "+freq+"]"; // } // // public int x; // public int y; // public int z; // public int freq; // }
import java.util.TreeSet; import codechicken.wirelessredstone.core.FreqCoord;
package codechicken.wirelessredstone.addons; public class WirelessMapNodeStorage { public void clear() { nodes.clear(); devices.clear(); }
// Path: src/codechicken/wirelessredstone/core/FreqCoord.java // public class FreqCoord implements Comparable<FreqCoord> // { // public FreqCoord(int x, int y, int z, int freq) // { // this.x = x; // this.y = y; // this.z = z; // this.freq = freq; // } // // public FreqCoord(ITileWireless itile) // { // TileEntity tile = (TileEntity)itile; // x = tile.xCoord; // y = tile.yCoord; // z = tile.zCoord; // freq = itile.getFreq(); // } // // public FreqCoord(BlockCoord node, int freq) // { // x = node.x; // y = node.y; // z = node.z; // this.freq = freq; // } // // public int compareTo(FreqCoord node2) // { // if(freq != node2.freq) return freq < node2.freq ? -1 : 1; // if(x != node2.x) return x < node2.x ? -1 : 1; // if(z != node2.z) return z < node2.z ? -1 : 1; // if(y != node2.y) return y < node2.y ? -1 : 1; // return 0; // } // // public String toString() // { // return "["+x+","+y+","+z+" on "+freq+"]"; // } // // public int x; // public int y; // public int z; // public int freq; // } // Path: src/codechicken/wirelessredstone/addons/WirelessMapNodeStorage.java import java.util.TreeSet; import codechicken.wirelessredstone.core.FreqCoord; package codechicken.wirelessredstone.addons; public class WirelessMapNodeStorage { public void clear() { nodes.clear(); devices.clear(); }
public TreeSet<FreqCoord> nodes = new TreeSet<FreqCoord>();
heroku/heroku.jar
heroku-api-integration-tests/src/test/java/com/heroku/api/ConnectionTestModule.java
// Path: heroku-api/src/main/java/com/heroku/api/connection/Connection.java // public interface Connection { // // // /** // * Synchronously execute the given request, using a different apiKey than the one associated with this connection // * // * @param request the request to execute // * @param <T> the response type // * @param apiKey the apiKey of the user to make the request on behalf of // * @return the response as parsed by the request object // */ // <T> T execute(Request<T> request, String apiKey); // // // /** // * Synchronously execute the given request, using a different apiKey than the one associated with this connection // * // * @param request the request to execute // * @param <T> the response type // * @param extraHeaders any extra headers to send with the request // * @param apiKey the apiKey of the user to make the request on behalf of // * @return the response as parsed by the request object // */ // <T> T execute(Request<T> request, Map<String,String> extraHeaders, String apiKey); // // /** // * Release any resources associated with this connection // */ // void close(); // // }
import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.heroku.api.connection.Connection; import java.io.IOException;
package com.heroku.api; /** * Guice Module for providing tests with authentication information. * * @author Naaman Newbold */ public abstract class ConnectionTestModule extends AbstractModule { @Override protected void configure() { }
// Path: heroku-api/src/main/java/com/heroku/api/connection/Connection.java // public interface Connection { // // // /** // * Synchronously execute the given request, using a different apiKey than the one associated with this connection // * // * @param request the request to execute // * @param <T> the response type // * @param apiKey the apiKey of the user to make the request on behalf of // * @return the response as parsed by the request object // */ // <T> T execute(Request<T> request, String apiKey); // // // /** // * Synchronously execute the given request, using a different apiKey than the one associated with this connection // * // * @param request the request to execute // * @param <T> the response type // * @param extraHeaders any extra headers to send with the request // * @param apiKey the apiKey of the user to make the request on behalf of // * @return the response as parsed by the request object // */ // <T> T execute(Request<T> request, Map<String,String> extraHeaders, String apiKey); // // /** // * Release any resources associated with this connection // */ // void close(); // // } // Path: heroku-api-integration-tests/src/test/java/com/heroku/api/ConnectionTestModule.java import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.heroku.api.connection.Connection; import java.io.IOException; package com.heroku.api; /** * Guice Module for providing tests with authentication information. * * @author Naaman Newbold */ public abstract class ConnectionTestModule extends AbstractModule { @Override protected void configure() { }
abstract Connection getConnectionImpl() throws IOException;
heroku/heroku.jar
heroku-api-integration-tests/src/test/java/com/heroku/api/TestModuleFactory.java
// Path: heroku-json-gson/src/main/java/com/heroku/api/parser/GsonParser.java // public class GsonParser implements Parser { // // @Override // public String encode(Object object) { // GsonBuilder builder = new GsonBuilder(); // // Gson gson = builder.create(); // return gson.toJson(object); // } // // @Override // public <T> T parse(byte[] data, final Type type) { // Reader dataReader = getReader(data); // JsonReader jsonReader = new JsonReader(dataReader); // jsonReader.setLenient(true); // return new Gson().<T>fromJson(jsonReader, type); // } // // private Reader getReader(byte[] raw) { // try { // return new InputStreamReader(new ByteArrayInputStream(raw), "UTF-8"); // } catch (UnsupportedEncodingException e) { // throw new RuntimeException("Somehow UTF-8 is unsupported", e); // } // } // } // // Path: heroku-json-jackson/src/main/java/com/heroku/api/parser/JacksonParser.java // public class JacksonParser implements Parser { // @Override // public String encode(Object object) { // ObjectMapper mapper = new ObjectMapper(); // mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() // .withFieldVisibility(JsonAutoDetect.Visibility.NONE) // .withGetterVisibility(JsonAutoDetect.Visibility.ANY) // .withSetterVisibility(JsonAutoDetect.Visibility.NONE) // .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); // try { // return mapper.writeValueAsString(object); // } catch (IOException e) { // throw new ParseException("Unable to encode object.", e); // } // } // // @Override // public <T> T parse(byte[] data, Type type) { // ObjectMapper mapper = new ObjectMapper(); // mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // JavaType javaType = mapper.constructType(type); // try { // return mapper.readValue(data, javaType); // } catch (IOException e) { // throw new ParseException("Unable to parse data.", e); // } // } // }
import com.google.inject.Module; import com.heroku.api.parser.GsonParser; import com.heroku.api.parser.JacksonParser; import org.testng.IModuleFactory; import org.testng.ITestContext;
package com.heroku.api; public class TestModuleFactory implements IModuleFactory { @Override public Module createModule(ITestContext iTestContext, Class<?> aClass) { if (iTestContext.getCurrentXmlTest().getName().contains("finagle")) { return new FinagleModule(); } else if (iTestContext.getCurrentXmlTest().getName().contains("asynchttp")) { return new AsyncHttpClientModule(); } else if (iTestContext.getCurrentXmlTest().getName().contains("jackson")) {
// Path: heroku-json-gson/src/main/java/com/heroku/api/parser/GsonParser.java // public class GsonParser implements Parser { // // @Override // public String encode(Object object) { // GsonBuilder builder = new GsonBuilder(); // // Gson gson = builder.create(); // return gson.toJson(object); // } // // @Override // public <T> T parse(byte[] data, final Type type) { // Reader dataReader = getReader(data); // JsonReader jsonReader = new JsonReader(dataReader); // jsonReader.setLenient(true); // return new Gson().<T>fromJson(jsonReader, type); // } // // private Reader getReader(byte[] raw) { // try { // return new InputStreamReader(new ByteArrayInputStream(raw), "UTF-8"); // } catch (UnsupportedEncodingException e) { // throw new RuntimeException("Somehow UTF-8 is unsupported", e); // } // } // } // // Path: heroku-json-jackson/src/main/java/com/heroku/api/parser/JacksonParser.java // public class JacksonParser implements Parser { // @Override // public String encode(Object object) { // ObjectMapper mapper = new ObjectMapper(); // mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() // .withFieldVisibility(JsonAutoDetect.Visibility.NONE) // .withGetterVisibility(JsonAutoDetect.Visibility.ANY) // .withSetterVisibility(JsonAutoDetect.Visibility.NONE) // .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); // try { // return mapper.writeValueAsString(object); // } catch (IOException e) { // throw new ParseException("Unable to encode object.", e); // } // } // // @Override // public <T> T parse(byte[] data, Type type) { // ObjectMapper mapper = new ObjectMapper(); // mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // JavaType javaType = mapper.constructType(type); // try { // return mapper.readValue(data, javaType); // } catch (IOException e) { // throw new ParseException("Unable to parse data.", e); // } // } // } // Path: heroku-api-integration-tests/src/test/java/com/heroku/api/TestModuleFactory.java import com.google.inject.Module; import com.heroku.api.parser.GsonParser; import com.heroku.api.parser.JacksonParser; import org.testng.IModuleFactory; import org.testng.ITestContext; package com.heroku.api; public class TestModuleFactory implements IModuleFactory { @Override public Module createModule(ITestContext iTestContext, Class<?> aClass) { if (iTestContext.getCurrentXmlTest().getName().contains("finagle")) { return new FinagleModule(); } else if (iTestContext.getCurrentXmlTest().getName().contains("asynchttp")) { return new AsyncHttpClientModule(); } else if (iTestContext.getCurrentXmlTest().getName().contains("jackson")) {
return new HttpClientModule(new JacksonParser());
heroku/heroku.jar
heroku-api-integration-tests/src/test/java/com/heroku/api/TestModuleFactory.java
// Path: heroku-json-gson/src/main/java/com/heroku/api/parser/GsonParser.java // public class GsonParser implements Parser { // // @Override // public String encode(Object object) { // GsonBuilder builder = new GsonBuilder(); // // Gson gson = builder.create(); // return gson.toJson(object); // } // // @Override // public <T> T parse(byte[] data, final Type type) { // Reader dataReader = getReader(data); // JsonReader jsonReader = new JsonReader(dataReader); // jsonReader.setLenient(true); // return new Gson().<T>fromJson(jsonReader, type); // } // // private Reader getReader(byte[] raw) { // try { // return new InputStreamReader(new ByteArrayInputStream(raw), "UTF-8"); // } catch (UnsupportedEncodingException e) { // throw new RuntimeException("Somehow UTF-8 is unsupported", e); // } // } // } // // Path: heroku-json-jackson/src/main/java/com/heroku/api/parser/JacksonParser.java // public class JacksonParser implements Parser { // @Override // public String encode(Object object) { // ObjectMapper mapper = new ObjectMapper(); // mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() // .withFieldVisibility(JsonAutoDetect.Visibility.NONE) // .withGetterVisibility(JsonAutoDetect.Visibility.ANY) // .withSetterVisibility(JsonAutoDetect.Visibility.NONE) // .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); // try { // return mapper.writeValueAsString(object); // } catch (IOException e) { // throw new ParseException("Unable to encode object.", e); // } // } // // @Override // public <T> T parse(byte[] data, Type type) { // ObjectMapper mapper = new ObjectMapper(); // mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // JavaType javaType = mapper.constructType(type); // try { // return mapper.readValue(data, javaType); // } catch (IOException e) { // throw new ParseException("Unable to parse data.", e); // } // } // }
import com.google.inject.Module; import com.heroku.api.parser.GsonParser; import com.heroku.api.parser.JacksonParser; import org.testng.IModuleFactory; import org.testng.ITestContext;
package com.heroku.api; public class TestModuleFactory implements IModuleFactory { @Override public Module createModule(ITestContext iTestContext, Class<?> aClass) { if (iTestContext.getCurrentXmlTest().getName().contains("finagle")) { return new FinagleModule(); } else if (iTestContext.getCurrentXmlTest().getName().contains("asynchttp")) { return new AsyncHttpClientModule(); } else if (iTestContext.getCurrentXmlTest().getName().contains("jackson")) { return new HttpClientModule(new JacksonParser()); } else {
// Path: heroku-json-gson/src/main/java/com/heroku/api/parser/GsonParser.java // public class GsonParser implements Parser { // // @Override // public String encode(Object object) { // GsonBuilder builder = new GsonBuilder(); // // Gson gson = builder.create(); // return gson.toJson(object); // } // // @Override // public <T> T parse(byte[] data, final Type type) { // Reader dataReader = getReader(data); // JsonReader jsonReader = new JsonReader(dataReader); // jsonReader.setLenient(true); // return new Gson().<T>fromJson(jsonReader, type); // } // // private Reader getReader(byte[] raw) { // try { // return new InputStreamReader(new ByteArrayInputStream(raw), "UTF-8"); // } catch (UnsupportedEncodingException e) { // throw new RuntimeException("Somehow UTF-8 is unsupported", e); // } // } // } // // Path: heroku-json-jackson/src/main/java/com/heroku/api/parser/JacksonParser.java // public class JacksonParser implements Parser { // @Override // public String encode(Object object) { // ObjectMapper mapper = new ObjectMapper(); // mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() // .withFieldVisibility(JsonAutoDetect.Visibility.NONE) // .withGetterVisibility(JsonAutoDetect.Visibility.ANY) // .withSetterVisibility(JsonAutoDetect.Visibility.NONE) // .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); // try { // return mapper.writeValueAsString(object); // } catch (IOException e) { // throw new ParseException("Unable to encode object.", e); // } // } // // @Override // public <T> T parse(byte[] data, Type type) { // ObjectMapper mapper = new ObjectMapper(); // mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // JavaType javaType = mapper.constructType(type); // try { // return mapper.readValue(data, javaType); // } catch (IOException e) { // throw new ParseException("Unable to parse data.", e); // } // } // } // Path: heroku-api-integration-tests/src/test/java/com/heroku/api/TestModuleFactory.java import com.google.inject.Module; import com.heroku.api.parser.GsonParser; import com.heroku.api.parser.JacksonParser; import org.testng.IModuleFactory; import org.testng.ITestContext; package com.heroku.api; public class TestModuleFactory implements IModuleFactory { @Override public Module createModule(ITestContext iTestContext, Class<?> aClass) { if (iTestContext.getCurrentXmlTest().getName().contains("finagle")) { return new FinagleModule(); } else if (iTestContext.getCurrentXmlTest().getName().contains("asynchttp")) { return new AsyncHttpClientModule(); } else if (iTestContext.getCurrentXmlTest().getName().contains("jackson")) { return new HttpClientModule(new JacksonParser()); } else {
return new HttpClientModule(new GsonParser());
heroku/heroku.jar
heroku-json-jersey-client/src/main/java/com/heroku/api/parser/JerseyClientJsonParser.java
// Path: heroku-api/src/main/java/com/heroku/api/exception/ParseException.java // public class ParseException extends HerokuAPIException { // public ParseException(String msg) { // super(msg); // } // // public ParseException(Throwable throwable) { // super(throwable); // } // // public ParseException(String msg, Throwable throwable) { // super(msg, throwable); // } // }
import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.heroku.api.exception.ParseException; import java.io.IOException; import java.lang.reflect.Type;
package com.heroku.api.parser; /** * @author Ryan Brainard */ public class JerseyClientJsonParser implements Parser { @Override public String encode(Object object) { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.NONE) .withGetterVisibility(JsonAutoDetect.Visibility.ANY) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); try { return mapper.writeValueAsString(object); } catch (IOException e) {
// Path: heroku-api/src/main/java/com/heroku/api/exception/ParseException.java // public class ParseException extends HerokuAPIException { // public ParseException(String msg) { // super(msg); // } // // public ParseException(Throwable throwable) { // super(throwable); // } // // public ParseException(String msg, Throwable throwable) { // super(msg, throwable); // } // } // Path: heroku-json-jersey-client/src/main/java/com/heroku/api/parser/JerseyClientJsonParser.java import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.heroku.api.exception.ParseException; import java.io.IOException; import java.lang.reflect.Type; package com.heroku.api.parser; /** * @author Ryan Brainard */ public class JerseyClientJsonParser implements Parser { @Override public String encode(Object object) { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.NONE) .withGetterVisibility(JsonAutoDetect.Visibility.ANY) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); try { return mapper.writeValueAsString(object); } catch (IOException e) {
throw new ParseException("Unable to encode object.", e);
heroku/heroku.jar
heroku-api/src/main/java/com/heroku/api/request/RequestTransformation.java
// Path: heroku-api/src/main/java/com/heroku/api/http/Http.java // public class Http { // /** // * HTTP Accept header model. // */ // public static enum Accept implements Header { // JSON("application/json"), // TEXT("text/plain"); // // private String value; // static String ACCEPT = "Accept"; // // Accept(String val) { // this.value = val; // } // // @Override // public String getHeaderName() { // return ACCEPT; // } // // @Override // public String getHeaderValue() { // return value; // } // // } // // /** // * HTTP Content-Type header model. // */ // public static enum ContentType implements Header { // JSON("application/json"), // FORM_URLENCODED("application/x-www-form-urlencoded"), // SSH_AUTHKEY("text/ssh-authkey"); // // private String value; // static String CONTENT_TYPE = "Content-Type"; // // ContentType(String val) { // this.value = val; // } // // @Override // public String getHeaderName() { // return CONTENT_TYPE; // } // // @Override // public String getHeaderValue() { // return value; // } // // } // // /** // * HTTP User-Agent header model. // * // * @see UserAgentValueProvider // */ // public static enum UserAgent implements Header { // LATEST(loadValueProvider()); // // static final String USER_AGENT = "User-Agent"; // private final UserAgentValueProvider userAgentValueProvider; // // UserAgent(UserAgentValueProvider userAgentValueProvider) { // this.userAgentValueProvider = userAgentValueProvider; // } // // @Override // public String getHeaderName() { // return USER_AGENT; // } // // @Override // public String getHeaderValue() { // return userAgentValueProvider.getHeaderValue(); // } // // public String getHeaderValue(String customPart) { // return userAgentValueProvider.getHeaderValue(customPart); // } // // private static UserAgentValueProvider loadValueProvider() { // final Iterator<UserAgentValueProvider> customProviders = // ServiceLoader.load(UserAgentValueProvider.class, UserAgent.class.getClassLoader()).iterator(); // // if (customProviders.hasNext()) { // return customProviders.next(); // } else { // return new UserAgentValueProvider.DEFAULT(); // } // } // } // // /** // * Represent a name/value pair for a HTTP header. Not all are implemented. Only those used by the Heroku API. // */ // public static interface Header { // // public static class Util { // public static Map<String, String> setHeaders(Header... headers) { // Map<String, String> headerMap = new HashMap<String, String>(); // for (Header h : headers) { // headerMap.put(h.getHeaderName(), h.getHeaderValue()); // } // return headerMap; // } // } // // String getHeaderName(); // // String getHeaderValue(); // // } // // /** // * HTTP Methods. Not all are implemented. Only those used by the Heroku API. // */ // public static enum Method {GET, PUT, POST, DELETE, PATCH} // // /** // * HTTP Status codes. Not all are implemented. Only those used by the Heroku API. // */ // public static enum Status { // OK(200), CREATED(201), ACCEPTED(202), PAYMENT_REQUIRED(402), FORBIDDEN(403), NOT_FOUND(404), UNPROCESSABLE_ENTITY(422), INTERNAL_SERVER_ERROR(500), SERVICE_UNAVAILABLE(503); // // public final int statusCode; // // Status(int statusCode) { // this.statusCode = statusCode; // } // // public boolean equals(int code) { // return statusCode == code; // } // } // }
import com.heroku.api.http.Http; import java.util.Map;
package com.heroku.api.request; /** * Transforms a {@link Request}<code>&lt;A&gt;</code> into a {@link Request}<code>&lt;B&gt;</code> * to allow parsing of the raw response to create a <code>B</code>. * * This is useful for extending standard request classes with a different response type. * * @author Ryan Brainard */ public abstract class RequestTransformation<A,B> implements Request<B> { private final Request<A> a; public RequestTransformation(Request<A> a) { this.a = a; } @Override
// Path: heroku-api/src/main/java/com/heroku/api/http/Http.java // public class Http { // /** // * HTTP Accept header model. // */ // public static enum Accept implements Header { // JSON("application/json"), // TEXT("text/plain"); // // private String value; // static String ACCEPT = "Accept"; // // Accept(String val) { // this.value = val; // } // // @Override // public String getHeaderName() { // return ACCEPT; // } // // @Override // public String getHeaderValue() { // return value; // } // // } // // /** // * HTTP Content-Type header model. // */ // public static enum ContentType implements Header { // JSON("application/json"), // FORM_URLENCODED("application/x-www-form-urlencoded"), // SSH_AUTHKEY("text/ssh-authkey"); // // private String value; // static String CONTENT_TYPE = "Content-Type"; // // ContentType(String val) { // this.value = val; // } // // @Override // public String getHeaderName() { // return CONTENT_TYPE; // } // // @Override // public String getHeaderValue() { // return value; // } // // } // // /** // * HTTP User-Agent header model. // * // * @see UserAgentValueProvider // */ // public static enum UserAgent implements Header { // LATEST(loadValueProvider()); // // static final String USER_AGENT = "User-Agent"; // private final UserAgentValueProvider userAgentValueProvider; // // UserAgent(UserAgentValueProvider userAgentValueProvider) { // this.userAgentValueProvider = userAgentValueProvider; // } // // @Override // public String getHeaderName() { // return USER_AGENT; // } // // @Override // public String getHeaderValue() { // return userAgentValueProvider.getHeaderValue(); // } // // public String getHeaderValue(String customPart) { // return userAgentValueProvider.getHeaderValue(customPart); // } // // private static UserAgentValueProvider loadValueProvider() { // final Iterator<UserAgentValueProvider> customProviders = // ServiceLoader.load(UserAgentValueProvider.class, UserAgent.class.getClassLoader()).iterator(); // // if (customProviders.hasNext()) { // return customProviders.next(); // } else { // return new UserAgentValueProvider.DEFAULT(); // } // } // } // // /** // * Represent a name/value pair for a HTTP header. Not all are implemented. Only those used by the Heroku API. // */ // public static interface Header { // // public static class Util { // public static Map<String, String> setHeaders(Header... headers) { // Map<String, String> headerMap = new HashMap<String, String>(); // for (Header h : headers) { // headerMap.put(h.getHeaderName(), h.getHeaderValue()); // } // return headerMap; // } // } // // String getHeaderName(); // // String getHeaderValue(); // // } // // /** // * HTTP Methods. Not all are implemented. Only those used by the Heroku API. // */ // public static enum Method {GET, PUT, POST, DELETE, PATCH} // // /** // * HTTP Status codes. Not all are implemented. Only those used by the Heroku API. // */ // public static enum Status { // OK(200), CREATED(201), ACCEPTED(202), PAYMENT_REQUIRED(402), FORBIDDEN(403), NOT_FOUND(404), UNPROCESSABLE_ENTITY(422), INTERNAL_SERVER_ERROR(500), SERVICE_UNAVAILABLE(503); // // public final int statusCode; // // Status(int statusCode) { // this.statusCode = statusCode; // } // // public boolean equals(int code) { // return statusCode == code; // } // } // } // Path: heroku-api/src/main/java/com/heroku/api/request/RequestTransformation.java import com.heroku.api.http.Http; import java.util.Map; package com.heroku.api.request; /** * Transforms a {@link Request}<code>&lt;A&gt;</code> into a {@link Request}<code>&lt;B&gt;</code> * to allow parsing of the raw response to create a <code>B</code>. * * This is useful for extending standard request classes with a different response type. * * @author Ryan Brainard */ public abstract class RequestTransformation<A,B> implements Request<B> { private final Request<A> a; public RequestTransformation(Request<A> a) { this.a = a; } @Override
public Http.Method getHttpMethod() {
heroku/heroku.jar
heroku-api/src/main/java/com/heroku/api/exception/RequestFailedException.java
// Path: heroku-api/src/main/java/com/heroku/api/http/HttpUtil.java // public class HttpUtil { // // private static String ENCODE_FAIL = "Unsupported encoding exception while encoding parameters"; // // /** // * URL encode request paramaters from a {@link RequestConfig}. // * @param config Name/value pairs for a HTTP request. // * @param keys List of keys in the config to encode. // * @return A string representation of encoded name/value parameters. // */ // public static String encodeParameters(RequestConfig config, Heroku.RequestKey... keys) { // // StringBuilder encodedParameters = new StringBuilder(); // String separator = ""; // for (Heroku.RequestKey key : keys) { // if (config.get(key) != null) { // encodedParameters.append(separator); // encodedParameters.append(urlencode(key.queryParameter, ENCODE_FAIL)); // encodedParameters.append("="); // encodedParameters.append(urlencode(config.get(key), ENCODE_FAIL)); // separator = "&"; // } // } // return new String(encodedParameters); // // } // // // Characters to encode that URLEncoder doesn't encode. // // See: http://docs.oracle.com/javase/6/docs/api/java/net/URLEncoder.html // static final Map<String, String> specialChars = Collections.unmodifiableMap(new HashMap<String, String>(){{ // put(".", "%2e"); // put("-", "%2d"); // put("*", "%2a"); // put("_", "%5f"); // }}); // // /** // * Some calls in the Heroku API decode strings in a different way from URLEncoder. This is a method for handling those // * special cases. First, urlencode() is called. Then, .-*_ are replaced with their hexadecimal equivalent. // * @param toEncode string to encode // * @return A string representation of encoded parameters. // */ // public static String encodeIncludingSpecialCharacters(String toEncode) { // String encoded = urlencode(toEncode, "Unable to urlencode " + toEncode); // for (Map.Entry<String, String> s : specialChars.entrySet()) { // encoded = encoded.replace(s.getKey(), s.getValue()); // } // return encoded; // } // // public static String urlencode(String toEncode, String messageIfFails) { // try { // return URLEncoder.encode(toEncode, "UTF-8"); // } catch (UnsupportedEncodingException e) { // throw new RuntimeException(messageIfFails, e); // } // } // // // public static UnsupportedOperationException noBody() { // return new UnsupportedOperationException("This request does not have a body. Use hasBody() to check for a body."); // } // // public static URL toURL(String url) { // try { // return new URL(url); // } catch (MalformedURLException e) { // throw new RuntimeException("The URL was malformed: " + url, e); // } // } // // public static RequestFailedException insufficientPrivileges(int code, byte[] bytes) { // return new RequestFailedException("Insufficient privileges.", code, bytes); // } // // /** // * Converts an {@link InputStream} to a byte array // * @param in input stream to convert // * @return byte array // */ // public static byte[] getBytes(InputStream in) { // ByteArrayOutputStream os = new ByteArrayOutputStream(); // WritableByteChannel wbc = Channels.newChannel(os); // ReadableByteChannel rbc = Channels.newChannel(in); // ByteBuffer byteBuffer = ByteBuffer.allocate(1024); // try { // while (rbc.read(byteBuffer) != -1) { // byteBuffer.flip(); // wbc.write(byteBuffer); // byteBuffer.clear(); // } // wbc.close(); // rbc.close(); // return os.toByteArray(); // } catch (IOException e) { // throw new HerokuAPIException("IOException while reading response", e); // } // } // // public static String getUTF8String(byte[] in) { // try { // return new String(in, "UTF-8"); // } catch (UnsupportedEncodingException e) { // throw new HerokuAPIException("Somehow UTF-8 is unsupported", e); // } // } // }
import com.heroku.api.http.HttpUtil;
package com.heroku.api.exception; /** * Exception for {@link com.heroku.api.request.Request} failures. These include, but are not limited to * {@link java.io.IOException} and errors from the API. */ public class RequestFailedException extends HerokuAPIException { String responseBody; int statusCode; public RequestFailedException(String msg, int code, byte[] in) { this(msg, code, getBodyFromInput(in)); } private static String getBodyFromInput(byte[] in) { try {
// Path: heroku-api/src/main/java/com/heroku/api/http/HttpUtil.java // public class HttpUtil { // // private static String ENCODE_FAIL = "Unsupported encoding exception while encoding parameters"; // // /** // * URL encode request paramaters from a {@link RequestConfig}. // * @param config Name/value pairs for a HTTP request. // * @param keys List of keys in the config to encode. // * @return A string representation of encoded name/value parameters. // */ // public static String encodeParameters(RequestConfig config, Heroku.RequestKey... keys) { // // StringBuilder encodedParameters = new StringBuilder(); // String separator = ""; // for (Heroku.RequestKey key : keys) { // if (config.get(key) != null) { // encodedParameters.append(separator); // encodedParameters.append(urlencode(key.queryParameter, ENCODE_FAIL)); // encodedParameters.append("="); // encodedParameters.append(urlencode(config.get(key), ENCODE_FAIL)); // separator = "&"; // } // } // return new String(encodedParameters); // // } // // // Characters to encode that URLEncoder doesn't encode. // // See: http://docs.oracle.com/javase/6/docs/api/java/net/URLEncoder.html // static final Map<String, String> specialChars = Collections.unmodifiableMap(new HashMap<String, String>(){{ // put(".", "%2e"); // put("-", "%2d"); // put("*", "%2a"); // put("_", "%5f"); // }}); // // /** // * Some calls in the Heroku API decode strings in a different way from URLEncoder. This is a method for handling those // * special cases. First, urlencode() is called. Then, .-*_ are replaced with their hexadecimal equivalent. // * @param toEncode string to encode // * @return A string representation of encoded parameters. // */ // public static String encodeIncludingSpecialCharacters(String toEncode) { // String encoded = urlencode(toEncode, "Unable to urlencode " + toEncode); // for (Map.Entry<String, String> s : specialChars.entrySet()) { // encoded = encoded.replace(s.getKey(), s.getValue()); // } // return encoded; // } // // public static String urlencode(String toEncode, String messageIfFails) { // try { // return URLEncoder.encode(toEncode, "UTF-8"); // } catch (UnsupportedEncodingException e) { // throw new RuntimeException(messageIfFails, e); // } // } // // // public static UnsupportedOperationException noBody() { // return new UnsupportedOperationException("This request does not have a body. Use hasBody() to check for a body."); // } // // public static URL toURL(String url) { // try { // return new URL(url); // } catch (MalformedURLException e) { // throw new RuntimeException("The URL was malformed: " + url, e); // } // } // // public static RequestFailedException insufficientPrivileges(int code, byte[] bytes) { // return new RequestFailedException("Insufficient privileges.", code, bytes); // } // // /** // * Converts an {@link InputStream} to a byte array // * @param in input stream to convert // * @return byte array // */ // public static byte[] getBytes(InputStream in) { // ByteArrayOutputStream os = new ByteArrayOutputStream(); // WritableByteChannel wbc = Channels.newChannel(os); // ReadableByteChannel rbc = Channels.newChannel(in); // ByteBuffer byteBuffer = ByteBuffer.allocate(1024); // try { // while (rbc.read(byteBuffer) != -1) { // byteBuffer.flip(); // wbc.write(byteBuffer); // byteBuffer.clear(); // } // wbc.close(); // rbc.close(); // return os.toByteArray(); // } catch (IOException e) { // throw new HerokuAPIException("IOException while reading response", e); // } // } // // public static String getUTF8String(byte[] in) { // try { // return new String(in, "UTF-8"); // } catch (UnsupportedEncodingException e) { // throw new HerokuAPIException("Somehow UTF-8 is unsupported", e); // } // } // } // Path: heroku-api/src/main/java/com/heroku/api/exception/RequestFailedException.java import com.heroku.api.http.HttpUtil; package com.heroku.api.exception; /** * Exception for {@link com.heroku.api.request.Request} failures. These include, but are not limited to * {@link java.io.IOException} and errors from the API. */ public class RequestFailedException extends HerokuAPIException { String responseBody; int statusCode; public RequestFailedException(String msg, int code, byte[] in) { this(msg, code, getBodyFromInput(in)); } private static String getBodyFromInput(byte[] in) { try {
return HttpUtil.getUTF8String(in);
heroku/heroku.jar
heroku-http-ning-async/src/main/java/com/heroku/api/connection/ListenableFutureConnection.java
// Path: heroku-api/src/main/java/com/heroku/api/request/Request.java // public interface Request<T> { // // // /** // * HTTP method. e.g. GET, POST, PUT, DELETE // * @return The HTTP method used in the request. // */ // Http.Method getHttpMethod(); // // /** // * Path and query parameters of a URL. // * @return The path and query parameters as a String. // */ // String getEndpoint(); // // /** // * Whether or not the request has a body. // * @return true if it has a request body, otherwise false // */ // boolean hasBody(); // // /** // * Value of the request body. // * @return Body // * @throws UnsupportedOperationException Generally thrown if {@link #hasBody()} returns false // */ // String getBody(); // // /** // * Value of the request body as a Map. // * @return Body // * @throws UnsupportedOperationException Generally thrown if {@link #hasBody()} returns false // */ // Map<String, ?> getBodyAsMap(); // // /** // * HTTP Accept header. // * @return The Accept header to be used in the request. Typically "application/json" or "text/xml" // * @see com.heroku.api.http.Http.Accept // */ // Http.Accept getResponseType(); // // /** // * {@link Map} of request-specific HTTP headers. // * @return Name/value pairs of HTTP headers. // */ // Map<String, String> getHeaders(); // // /** // * Response handler. // * @param bytes Data returned from the request. // * @param status HTTP status code. // * @return The type {@link T} as specified by an individual request. // * @throws com.heroku.api.exception.RequestFailedException Generally thrown when the HTTP status code is 4XX. // */ // T getResponse(byte[] bytes, int status, Map<String,String> headers); // // }
import com.heroku.api.request.Request; import org.asynchttpclient.ListenableFuture;
package com.heroku.api.connection; public interface ListenableFutureConnection extends AsyncConnection<ListenableFuture<?>> { @Override
// Path: heroku-api/src/main/java/com/heroku/api/request/Request.java // public interface Request<T> { // // // /** // * HTTP method. e.g. GET, POST, PUT, DELETE // * @return The HTTP method used in the request. // */ // Http.Method getHttpMethod(); // // /** // * Path and query parameters of a URL. // * @return The path and query parameters as a String. // */ // String getEndpoint(); // // /** // * Whether or not the request has a body. // * @return true if it has a request body, otherwise false // */ // boolean hasBody(); // // /** // * Value of the request body. // * @return Body // * @throws UnsupportedOperationException Generally thrown if {@link #hasBody()} returns false // */ // String getBody(); // // /** // * Value of the request body as a Map. // * @return Body // * @throws UnsupportedOperationException Generally thrown if {@link #hasBody()} returns false // */ // Map<String, ?> getBodyAsMap(); // // /** // * HTTP Accept header. // * @return The Accept header to be used in the request. Typically "application/json" or "text/xml" // * @see com.heroku.api.http.Http.Accept // */ // Http.Accept getResponseType(); // // /** // * {@link Map} of request-specific HTTP headers. // * @return Name/value pairs of HTTP headers. // */ // Map<String, String> getHeaders(); // // /** // * Response handler. // * @param bytes Data returned from the request. // * @param status HTTP status code. // * @return The type {@link T} as specified by an individual request. // * @throws com.heroku.api.exception.RequestFailedException Generally thrown when the HTTP status code is 4XX. // */ // T getResponse(byte[] bytes, int status, Map<String,String> headers); // // } // Path: heroku-http-ning-async/src/main/java/com/heroku/api/connection/ListenableFutureConnection.java import com.heroku.api.request.Request; import org.asynchttpclient.ListenableFuture; package com.heroku.api.connection; public interface ListenableFutureConnection extends AsyncConnection<ListenableFuture<?>> { @Override
<T> ListenableFuture<T> executeAsync(Request<T> request, String apiKey);
heroku/heroku.jar
heroku-api/src/test/java/com/heroku/api/http/HttpUtilTest.java
// Path: heroku-api/src/main/java/com/heroku/api/http/HttpUtil.java // public static String encodeIncludingSpecialCharacters(String toEncode) { // String encoded = urlencode(toEncode, "Unable to urlencode " + toEncode); // for (Map.Entry<String, String> s : specialChars.entrySet()) { // encoded = encoded.replace(s.getKey(), s.getValue()); // } // return encoded; // }
import org.testng.annotations.Test; import static com.heroku.api.http.HttpUtil.encodeIncludingSpecialCharacters; import static org.testng.Assert.assertEquals;
package com.heroku.api.http; /** * Tests for http related utility methods. * * @author Naaman Newbold */ public class HttpUtilTest { @Test public void encodeParametersIncludingSpecialCharactersShouldEncodePeriodDashAsteriskAndUnderscore() {
// Path: heroku-api/src/main/java/com/heroku/api/http/HttpUtil.java // public static String encodeIncludingSpecialCharacters(String toEncode) { // String encoded = urlencode(toEncode, "Unable to urlencode " + toEncode); // for (Map.Entry<String, String> s : specialChars.entrySet()) { // encoded = encoded.replace(s.getKey(), s.getValue()); // } // return encoded; // } // Path: heroku-api/src/test/java/com/heroku/api/http/HttpUtilTest.java import org.testng.annotations.Test; import static com.heroku.api.http.HttpUtil.encodeIncludingSpecialCharacters; import static org.testng.Assert.assertEquals; package com.heroku.api.http; /** * Tests for http related utility methods. * * @author Naaman Newbold */ public class HttpUtilTest { @Test public void encodeParametersIncludingSpecialCharactersShouldEncodePeriodDashAsteriskAndUnderscore() {
assertEquals("%2e%2d%2a%5f", encodeIncludingSpecialCharacters(".-*_"));
heroku/heroku.jar
heroku-api-integration-tests/src/test/java/com/heroku/api/IntegrationTestConfig.java
// Path: heroku-api-integration-tests/src/test/java/com/heroku/api/parser/JsonSelector.java // public class JsonSelector { // // public static void selectParser(Parser parser) { // Json.Holder.parser = parser; // } // // public static Parser getParser() { // return Json.Holder.parser; // } // // } // // Path: heroku-api/src/main/java/com/heroku/api/parser/Parser.java // public interface Parser { // // <T> T parse(byte[] data, Type type); // // String encode(Object object); // } // // Path: heroku-api/src/main/java/com/heroku/api/parser/TypeReference.java // public abstract class TypeReference<T> { // private final Type t; // // protected TypeReference() { // Type superclass = getClass().getGenericSuperclass(); // // if (superclass instanceof Class) // throw new RuntimeException("No type parameter supplied."); // // t = ((ParameterizedType) superclass).getActualTypeArguments()[0]; // } // // public Type getType() { // return t; // } // // }
import com.heroku.api.parser.JsonSelector; import com.heroku.api.parser.Parser; import com.heroku.api.parser.TypeReference; import java.util.ArrayList; import java.util.List; import static org.testng.Assert.assertNotNull;
* Gets a list of all users not marked as default:true. */ public List<TestUser> getOtherUsers() { if (otherUsers == null) { loadUsers(); } return otherUsers; } /** * Gets a user that is not the default user. */ public TestUser getOtherUser() { if (otherUsers == null) { loadUsers(); } return otherUsers.get(0); } public List<TestUser> getTestUsers() { if (testUsers == null) { loadUsers(); } return testUsers; } private void loadUsers() { assertConfigIsPresent();
// Path: heroku-api-integration-tests/src/test/java/com/heroku/api/parser/JsonSelector.java // public class JsonSelector { // // public static void selectParser(Parser parser) { // Json.Holder.parser = parser; // } // // public static Parser getParser() { // return Json.Holder.parser; // } // // } // // Path: heroku-api/src/main/java/com/heroku/api/parser/Parser.java // public interface Parser { // // <T> T parse(byte[] data, Type type); // // String encode(Object object); // } // // Path: heroku-api/src/main/java/com/heroku/api/parser/TypeReference.java // public abstract class TypeReference<T> { // private final Type t; // // protected TypeReference() { // Type superclass = getClass().getGenericSuperclass(); // // if (superclass instanceof Class) // throw new RuntimeException("No type parameter supplied."); // // t = ((ParameterizedType) superclass).getActualTypeArguments()[0]; // } // // public Type getType() { // return t; // } // // } // Path: heroku-api-integration-tests/src/test/java/com/heroku/api/IntegrationTestConfig.java import com.heroku.api.parser.JsonSelector; import com.heroku.api.parser.Parser; import com.heroku.api.parser.TypeReference; import java.util.ArrayList; import java.util.List; import static org.testng.Assert.assertNotNull; * Gets a list of all users not marked as default:true. */ public List<TestUser> getOtherUsers() { if (otherUsers == null) { loadUsers(); } return otherUsers; } /** * Gets a user that is not the default user. */ public TestUser getOtherUser() { if (otherUsers == null) { loadUsers(); } return otherUsers.get(0); } public List<TestUser> getTestUsers() { if (testUsers == null) { loadUsers(); } return testUsers; } private void loadUsers() { assertConfigIsPresent();
Parser jsonParser = JsonSelector.getParser();
heroku/heroku.jar
heroku-api-integration-tests/src/test/java/com/heroku/api/IntegrationTestConfig.java
// Path: heroku-api-integration-tests/src/test/java/com/heroku/api/parser/JsonSelector.java // public class JsonSelector { // // public static void selectParser(Parser parser) { // Json.Holder.parser = parser; // } // // public static Parser getParser() { // return Json.Holder.parser; // } // // } // // Path: heroku-api/src/main/java/com/heroku/api/parser/Parser.java // public interface Parser { // // <T> T parse(byte[] data, Type type); // // String encode(Object object); // } // // Path: heroku-api/src/main/java/com/heroku/api/parser/TypeReference.java // public abstract class TypeReference<T> { // private final Type t; // // protected TypeReference() { // Type superclass = getClass().getGenericSuperclass(); // // if (superclass instanceof Class) // throw new RuntimeException("No type parameter supplied."); // // t = ((ParameterizedType) superclass).getActualTypeArguments()[0]; // } // // public Type getType() { // return t; // } // // }
import com.heroku.api.parser.JsonSelector; import com.heroku.api.parser.Parser; import com.heroku.api.parser.TypeReference; import java.util.ArrayList; import java.util.List; import static org.testng.Assert.assertNotNull;
* Gets a list of all users not marked as default:true. */ public List<TestUser> getOtherUsers() { if (otherUsers == null) { loadUsers(); } return otherUsers; } /** * Gets a user that is not the default user. */ public TestUser getOtherUser() { if (otherUsers == null) { loadUsers(); } return otherUsers.get(0); } public List<TestUser> getTestUsers() { if (testUsers == null) { loadUsers(); } return testUsers; } private void loadUsers() { assertConfigIsPresent();
// Path: heroku-api-integration-tests/src/test/java/com/heroku/api/parser/JsonSelector.java // public class JsonSelector { // // public static void selectParser(Parser parser) { // Json.Holder.parser = parser; // } // // public static Parser getParser() { // return Json.Holder.parser; // } // // } // // Path: heroku-api/src/main/java/com/heroku/api/parser/Parser.java // public interface Parser { // // <T> T parse(byte[] data, Type type); // // String encode(Object object); // } // // Path: heroku-api/src/main/java/com/heroku/api/parser/TypeReference.java // public abstract class TypeReference<T> { // private final Type t; // // protected TypeReference() { // Type superclass = getClass().getGenericSuperclass(); // // if (superclass instanceof Class) // throw new RuntimeException("No type parameter supplied."); // // t = ((ParameterizedType) superclass).getActualTypeArguments()[0]; // } // // public Type getType() { // return t; // } // // } // Path: heroku-api-integration-tests/src/test/java/com/heroku/api/IntegrationTestConfig.java import com.heroku.api.parser.JsonSelector; import com.heroku.api.parser.Parser; import com.heroku.api.parser.TypeReference; import java.util.ArrayList; import java.util.List; import static org.testng.Assert.assertNotNull; * Gets a list of all users not marked as default:true. */ public List<TestUser> getOtherUsers() { if (otherUsers == null) { loadUsers(); } return otherUsers; } /** * Gets a user that is not the default user. */ public TestUser getOtherUser() { if (otherUsers == null) { loadUsers(); } return otherUsers.get(0); } public List<TestUser> getTestUsers() { if (testUsers == null) { loadUsers(); } return testUsers; } private void loadUsers() { assertConfigIsPresent();
Parser jsonParser = JsonSelector.getParser();
heroku/heroku.jar
heroku-api-integration-tests/src/test/java/com/heroku/api/IntegrationTestConfig.java
// Path: heroku-api-integration-tests/src/test/java/com/heroku/api/parser/JsonSelector.java // public class JsonSelector { // // public static void selectParser(Parser parser) { // Json.Holder.parser = parser; // } // // public static Parser getParser() { // return Json.Holder.parser; // } // // } // // Path: heroku-api/src/main/java/com/heroku/api/parser/Parser.java // public interface Parser { // // <T> T parse(byte[] data, Type type); // // String encode(Object object); // } // // Path: heroku-api/src/main/java/com/heroku/api/parser/TypeReference.java // public abstract class TypeReference<T> { // private final Type t; // // protected TypeReference() { // Type superclass = getClass().getGenericSuperclass(); // // if (superclass instanceof Class) // throw new RuntimeException("No type parameter supplied."); // // t = ((ParameterizedType) superclass).getActualTypeArguments()[0]; // } // // public Type getType() { // return t; // } // // }
import com.heroku.api.parser.JsonSelector; import com.heroku.api.parser.Parser; import com.heroku.api.parser.TypeReference; import java.util.ArrayList; import java.util.List; import static org.testng.Assert.assertNotNull;
*/ public List<TestUser> getOtherUsers() { if (otherUsers == null) { loadUsers(); } return otherUsers; } /** * Gets a user that is not the default user. */ public TestUser getOtherUser() { if (otherUsers == null) { loadUsers(); } return otherUsers.get(0); } public List<TestUser> getTestUsers() { if (testUsers == null) { loadUsers(); } return testUsers; } private void loadUsers() { assertConfigIsPresent(); Parser jsonParser = JsonSelector.getParser();
// Path: heroku-api-integration-tests/src/test/java/com/heroku/api/parser/JsonSelector.java // public class JsonSelector { // // public static void selectParser(Parser parser) { // Json.Holder.parser = parser; // } // // public static Parser getParser() { // return Json.Holder.parser; // } // // } // // Path: heroku-api/src/main/java/com/heroku/api/parser/Parser.java // public interface Parser { // // <T> T parse(byte[] data, Type type); // // String encode(Object object); // } // // Path: heroku-api/src/main/java/com/heroku/api/parser/TypeReference.java // public abstract class TypeReference<T> { // private final Type t; // // protected TypeReference() { // Type superclass = getClass().getGenericSuperclass(); // // if (superclass instanceof Class) // throw new RuntimeException("No type parameter supplied."); // // t = ((ParameterizedType) superclass).getActualTypeArguments()[0]; // } // // public Type getType() { // return t; // } // // } // Path: heroku-api-integration-tests/src/test/java/com/heroku/api/IntegrationTestConfig.java import com.heroku.api.parser.JsonSelector; import com.heroku.api.parser.Parser; import com.heroku.api.parser.TypeReference; import java.util.ArrayList; import java.util.List; import static org.testng.Assert.assertNotNull; */ public List<TestUser> getOtherUsers() { if (otherUsers == null) { loadUsers(); } return otherUsers; } /** * Gets a user that is not the default user. */ public TestUser getOtherUser() { if (otherUsers == null) { loadUsers(); } return otherUsers.get(0); } public List<TestUser> getTestUsers() { if (testUsers == null) { loadUsers(); } return testUsers; } private void loadUsers() { assertConfigIsPresent(); Parser jsonParser = JsonSelector.getParser();
testUsers = jsonParser.parse(getConfig().getBytes(), new TypeReference<List<TestUser>>() {
heroku/heroku.jar
heroku-json-jackson/src/main/java/com/heroku/api/parser/JacksonParser.java
// Path: heroku-api/src/main/java/com/heroku/api/exception/ParseException.java // public class ParseException extends HerokuAPIException { // public ParseException(String msg) { // super(msg); // } // // public ParseException(Throwable throwable) { // super(throwable); // } // // public ParseException(String msg, Throwable throwable) { // super(msg, throwable); // } // }
import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.heroku.api.exception.ParseException; import java.io.IOException; import java.lang.reflect.Type;
package com.heroku.api.parser; /** * * @author Naaman Newbold */ public class JacksonParser implements Parser { @Override public String encode(Object object) { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.NONE) .withGetterVisibility(JsonAutoDetect.Visibility.ANY) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); try { return mapper.writeValueAsString(object); } catch (IOException e) {
// Path: heroku-api/src/main/java/com/heroku/api/exception/ParseException.java // public class ParseException extends HerokuAPIException { // public ParseException(String msg) { // super(msg); // } // // public ParseException(Throwable throwable) { // super(throwable); // } // // public ParseException(String msg, Throwable throwable) { // super(msg, throwable); // } // } // Path: heroku-json-jackson/src/main/java/com/heroku/api/parser/JacksonParser.java import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.heroku.api.exception.ParseException; import java.io.IOException; import java.lang.reflect.Type; package com.heroku.api.parser; /** * * @author Naaman Newbold */ public class JacksonParser implements Parser { @Override public String encode(Object object) { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.NONE) .withGetterVisibility(JsonAutoDetect.Visibility.ANY) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); try { return mapper.writeValueAsString(object); } catch (IOException e) {
throw new ParseException("Unable to encode object.", e);
heroku/heroku.jar
heroku-http-apache/src/main/java/com/heroku/api/connection/FutureConnection.java
// Path: heroku-api/src/main/java/com/heroku/api/request/Request.java // public interface Request<T> { // // // /** // * HTTP method. e.g. GET, POST, PUT, DELETE // * @return The HTTP method used in the request. // */ // Http.Method getHttpMethod(); // // /** // * Path and query parameters of a URL. // * @return The path and query parameters as a String. // */ // String getEndpoint(); // // /** // * Whether or not the request has a body. // * @return true if it has a request body, otherwise false // */ // boolean hasBody(); // // /** // * Value of the request body. // * @return Body // * @throws UnsupportedOperationException Generally thrown if {@link #hasBody()} returns false // */ // String getBody(); // // /** // * Value of the request body as a Map. // * @return Body // * @throws UnsupportedOperationException Generally thrown if {@link #hasBody()} returns false // */ // Map<String, ?> getBodyAsMap(); // // /** // * HTTP Accept header. // * @return The Accept header to be used in the request. Typically "application/json" or "text/xml" // * @see com.heroku.api.http.Http.Accept // */ // Http.Accept getResponseType(); // // /** // * {@link Map} of request-specific HTTP headers. // * @return Name/value pairs of HTTP headers. // */ // Map<String, String> getHeaders(); // // /** // * Response handler. // * @param bytes Data returned from the request. // * @param status HTTP status code. // * @return The type {@link T} as specified by an individual request. // * @throws com.heroku.api.exception.RequestFailedException Generally thrown when the HTTP status code is 4XX. // */ // T getResponse(byte[] bytes, int status, Map<String,String> headers); // // }
import com.heroku.api.request.Request; import java.util.Map; import java.util.concurrent.Future;
package com.heroku.api.connection; public interface FutureConnection extends AsyncConnection<Future<?>> { @Override
// Path: heroku-api/src/main/java/com/heroku/api/request/Request.java // public interface Request<T> { // // // /** // * HTTP method. e.g. GET, POST, PUT, DELETE // * @return The HTTP method used in the request. // */ // Http.Method getHttpMethod(); // // /** // * Path and query parameters of a URL. // * @return The path and query parameters as a String. // */ // String getEndpoint(); // // /** // * Whether or not the request has a body. // * @return true if it has a request body, otherwise false // */ // boolean hasBody(); // // /** // * Value of the request body. // * @return Body // * @throws UnsupportedOperationException Generally thrown if {@link #hasBody()} returns false // */ // String getBody(); // // /** // * Value of the request body as a Map. // * @return Body // * @throws UnsupportedOperationException Generally thrown if {@link #hasBody()} returns false // */ // Map<String, ?> getBodyAsMap(); // // /** // * HTTP Accept header. // * @return The Accept header to be used in the request. Typically "application/json" or "text/xml" // * @see com.heroku.api.http.Http.Accept // */ // Http.Accept getResponseType(); // // /** // * {@link Map} of request-specific HTTP headers. // * @return Name/value pairs of HTTP headers. // */ // Map<String, String> getHeaders(); // // /** // * Response handler. // * @param bytes Data returned from the request. // * @param status HTTP status code. // * @return The type {@link T} as specified by an individual request. // * @throws com.heroku.api.exception.RequestFailedException Generally thrown when the HTTP status code is 4XX. // */ // T getResponse(byte[] bytes, int status, Map<String,String> headers); // // } // Path: heroku-http-apache/src/main/java/com/heroku/api/connection/FutureConnection.java import com.heroku.api.request.Request; import java.util.Map; import java.util.concurrent.Future; package com.heroku.api.connection; public interface FutureConnection extends AsyncConnection<Future<?>> { @Override
<T> Future<T> executeAsync(Request<T> request, String apiKey);
heroku/heroku.jar
heroku-api-integration-tests/src/test/java/com/heroku/api/FinagleModule.java
// Path: heroku-api/src/main/java/com/heroku/api/exception/RequestFailedException.java // public class RequestFailedException extends HerokuAPIException { // // String responseBody; // int statusCode; // // public RequestFailedException(String msg, int code, byte[] in) { // this(msg, code, getBodyFromInput(in)); // // } // // private static String getBodyFromInput(byte[] in) { // try { // return HttpUtil.getUTF8String(in); // } catch (Exception e) { // return "There was also an error reading the response body."; // } // } // // public RequestFailedException(String msg, int code, String body) { // super(msg + " statuscode:" + code + " responseBody:" + body); // responseBody = body; // statusCode = code; // } // // // public String getResponseBody() { // return responseBody; // } // // public int getStatusCode() { // return statusCode; // } // }
import com.google.inject.Provides; import com.heroku.api.connection.FinagleConnection; import com.heroku.api.connection.TwitterFutureConnection; import com.heroku.api.exception.RequestFailedException; import java.io.IOException;
package com.heroku.api; public class FinagleModule extends ConnectionTestModule { @Provides TwitterFutureConnection getConnectionImpl() throws IOException { try { return FinagleConnection.apply();
// Path: heroku-api/src/main/java/com/heroku/api/exception/RequestFailedException.java // public class RequestFailedException extends HerokuAPIException { // // String responseBody; // int statusCode; // // public RequestFailedException(String msg, int code, byte[] in) { // this(msg, code, getBodyFromInput(in)); // // } // // private static String getBodyFromInput(byte[] in) { // try { // return HttpUtil.getUTF8String(in); // } catch (Exception e) { // return "There was also an error reading the response body."; // } // } // // public RequestFailedException(String msg, int code, String body) { // super(msg + " statuscode:" + code + " responseBody:" + body); // responseBody = body; // statusCode = code; // } // // // public String getResponseBody() { // return responseBody; // } // // public int getStatusCode() { // return statusCode; // } // } // Path: heroku-api-integration-tests/src/test/java/com/heroku/api/FinagleModule.java import com.google.inject.Provides; import com.heroku.api.connection.FinagleConnection; import com.heroku.api.connection.TwitterFutureConnection; import com.heroku.api.exception.RequestFailedException; import java.io.IOException; package com.heroku.api; public class FinagleModule extends ConnectionTestModule { @Provides TwitterFutureConnection getConnectionImpl() throws IOException { try { return FinagleConnection.apply();
} catch (RequestFailedException e) {
heroku/heroku.jar
heroku-api/src/main/java/com/heroku/api/Heroku.java
// Path: heroku-api/src/main/java/com/heroku/api/exception/HerokuAPIException.java // public class HerokuAPIException extends RuntimeException { // // // public HerokuAPIException(String msg) { // super(msg); // } // // public HerokuAPIException(Throwable throwable) { // super(throwable); // } // // public HerokuAPIException(String msg, Throwable throwable) { // super(msg, throwable); // } // // // } // // Path: heroku-api/src/main/java/com/heroku/api/http/Http.java // public class Http { // /** // * HTTP Accept header model. // */ // public static enum Accept implements Header { // JSON("application/json"), // TEXT("text/plain"); // // private String value; // static String ACCEPT = "Accept"; // // Accept(String val) { // this.value = val; // } // // @Override // public String getHeaderName() { // return ACCEPT; // } // // @Override // public String getHeaderValue() { // return value; // } // // } // // /** // * HTTP Content-Type header model. // */ // public static enum ContentType implements Header { // JSON("application/json"), // FORM_URLENCODED("application/x-www-form-urlencoded"), // SSH_AUTHKEY("text/ssh-authkey"); // // private String value; // static String CONTENT_TYPE = "Content-Type"; // // ContentType(String val) { // this.value = val; // } // // @Override // public String getHeaderName() { // return CONTENT_TYPE; // } // // @Override // public String getHeaderValue() { // return value; // } // // } // // /** // * HTTP User-Agent header model. // * // * @see UserAgentValueProvider // */ // public static enum UserAgent implements Header { // LATEST(loadValueProvider()); // // static final String USER_AGENT = "User-Agent"; // private final UserAgentValueProvider userAgentValueProvider; // // UserAgent(UserAgentValueProvider userAgentValueProvider) { // this.userAgentValueProvider = userAgentValueProvider; // } // // @Override // public String getHeaderName() { // return USER_AGENT; // } // // @Override // public String getHeaderValue() { // return userAgentValueProvider.getHeaderValue(); // } // // public String getHeaderValue(String customPart) { // return userAgentValueProvider.getHeaderValue(customPart); // } // // private static UserAgentValueProvider loadValueProvider() { // final Iterator<UserAgentValueProvider> customProviders = // ServiceLoader.load(UserAgentValueProvider.class, UserAgent.class.getClassLoader()).iterator(); // // if (customProviders.hasNext()) { // return customProviders.next(); // } else { // return new UserAgentValueProvider.DEFAULT(); // } // } // } // // /** // * Represent a name/value pair for a HTTP header. Not all are implemented. Only those used by the Heroku API. // */ // public static interface Header { // // public static class Util { // public static Map<String, String> setHeaders(Header... headers) { // Map<String, String> headerMap = new HashMap<String, String>(); // for (Header h : headers) { // headerMap.put(h.getHeaderName(), h.getHeaderValue()); // } // return headerMap; // } // } // // String getHeaderName(); // // String getHeaderValue(); // // } // // /** // * HTTP Methods. Not all are implemented. Only those used by the Heroku API. // */ // public static enum Method {GET, PUT, POST, DELETE, PATCH} // // /** // * HTTP Status codes. Not all are implemented. Only those used by the Heroku API. // */ // public static enum Status { // OK(200), CREATED(201), ACCEPTED(202), PAYMENT_REQUIRED(402), FORBIDDEN(403), NOT_FOUND(404), UNPROCESSABLE_ENTITY(422), INTERNAL_SERVER_ERROR(500), SERVICE_UNAVAILABLE(503); // // public final int statusCode; // // Status(int statusCode) { // this.statusCode = statusCode; // } // // public boolean equals(int code) { // return statusCode == code; // } // } // }
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import java.io.IOException; import java.io.InputStream; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.cert.X509Certificate; import java.util.HashMap; import java.util.Map; import java.util.Properties; import com.heroku.api.exception.HerokuAPIException; import com.heroku.api.http.Http;
public static String getProperty(String propName) { return properties.getProperty(propName); } public static Properties getProperties() { return properties; } } public static SSLContext herokuSSLContext() { return sslContext(Config.ENDPOINT.isDefault()); } public static SSLContext sslContext(boolean verify) { try { SSLContext ctx = SSLContext.getInstance("TLS"); TrustManager[] tmgrs = null; if (!verify) { tmgrs = trustAllTrustManagers(); } /* Initializes this context. Either of the first two parameters may be null in which case the installed security providers will be searched for the highest priority implementation of the appropriate factory. Likewise, the secure random parameter may be null in which case the default implementation will be used. */ ctx.init(null, tmgrs, null); return ctx; } catch (NoSuchAlgorithmException e) {
// Path: heroku-api/src/main/java/com/heroku/api/exception/HerokuAPIException.java // public class HerokuAPIException extends RuntimeException { // // // public HerokuAPIException(String msg) { // super(msg); // } // // public HerokuAPIException(Throwable throwable) { // super(throwable); // } // // public HerokuAPIException(String msg, Throwable throwable) { // super(msg, throwable); // } // // // } // // Path: heroku-api/src/main/java/com/heroku/api/http/Http.java // public class Http { // /** // * HTTP Accept header model. // */ // public static enum Accept implements Header { // JSON("application/json"), // TEXT("text/plain"); // // private String value; // static String ACCEPT = "Accept"; // // Accept(String val) { // this.value = val; // } // // @Override // public String getHeaderName() { // return ACCEPT; // } // // @Override // public String getHeaderValue() { // return value; // } // // } // // /** // * HTTP Content-Type header model. // */ // public static enum ContentType implements Header { // JSON("application/json"), // FORM_URLENCODED("application/x-www-form-urlencoded"), // SSH_AUTHKEY("text/ssh-authkey"); // // private String value; // static String CONTENT_TYPE = "Content-Type"; // // ContentType(String val) { // this.value = val; // } // // @Override // public String getHeaderName() { // return CONTENT_TYPE; // } // // @Override // public String getHeaderValue() { // return value; // } // // } // // /** // * HTTP User-Agent header model. // * // * @see UserAgentValueProvider // */ // public static enum UserAgent implements Header { // LATEST(loadValueProvider()); // // static final String USER_AGENT = "User-Agent"; // private final UserAgentValueProvider userAgentValueProvider; // // UserAgent(UserAgentValueProvider userAgentValueProvider) { // this.userAgentValueProvider = userAgentValueProvider; // } // // @Override // public String getHeaderName() { // return USER_AGENT; // } // // @Override // public String getHeaderValue() { // return userAgentValueProvider.getHeaderValue(); // } // // public String getHeaderValue(String customPart) { // return userAgentValueProvider.getHeaderValue(customPart); // } // // private static UserAgentValueProvider loadValueProvider() { // final Iterator<UserAgentValueProvider> customProviders = // ServiceLoader.load(UserAgentValueProvider.class, UserAgent.class.getClassLoader()).iterator(); // // if (customProviders.hasNext()) { // return customProviders.next(); // } else { // return new UserAgentValueProvider.DEFAULT(); // } // } // } // // /** // * Represent a name/value pair for a HTTP header. Not all are implemented. Only those used by the Heroku API. // */ // public static interface Header { // // public static class Util { // public static Map<String, String> setHeaders(Header... headers) { // Map<String, String> headerMap = new HashMap<String, String>(); // for (Header h : headers) { // headerMap.put(h.getHeaderName(), h.getHeaderValue()); // } // return headerMap; // } // } // // String getHeaderName(); // // String getHeaderValue(); // // } // // /** // * HTTP Methods. Not all are implemented. Only those used by the Heroku API. // */ // public static enum Method {GET, PUT, POST, DELETE, PATCH} // // /** // * HTTP Status codes. Not all are implemented. Only those used by the Heroku API. // */ // public static enum Status { // OK(200), CREATED(201), ACCEPTED(202), PAYMENT_REQUIRED(402), FORBIDDEN(403), NOT_FOUND(404), UNPROCESSABLE_ENTITY(422), INTERNAL_SERVER_ERROR(500), SERVICE_UNAVAILABLE(503); // // public final int statusCode; // // Status(int statusCode) { // this.statusCode = statusCode; // } // // public boolean equals(int code) { // return statusCode == code; // } // } // } // Path: heroku-api/src/main/java/com/heroku/api/Heroku.java import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import java.io.IOException; import java.io.InputStream; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.cert.X509Certificate; import java.util.HashMap; import java.util.Map; import java.util.Properties; import com.heroku.api.exception.HerokuAPIException; import com.heroku.api.http.Http; public static String getProperty(String propName) { return properties.getProperty(propName); } public static Properties getProperties() { return properties; } } public static SSLContext herokuSSLContext() { return sslContext(Config.ENDPOINT.isDefault()); } public static SSLContext sslContext(boolean verify) { try { SSLContext ctx = SSLContext.getInstance("TLS"); TrustManager[] tmgrs = null; if (!verify) { tmgrs = trustAllTrustManagers(); } /* Initializes this context. Either of the first two parameters may be null in which case the installed security providers will be searched for the highest priority implementation of the appropriate factory. Likewise, the secure random parameter may be null in which case the default implementation will be used. */ ctx.init(null, tmgrs, null); return ctx; } catch (NoSuchAlgorithmException e) {
throw new HerokuAPIException("NoSuchAlgorithmException while trying to setup SSLContext", e);
heroku/heroku.jar
heroku-api/src/main/java/com/heroku/api/Heroku.java
// Path: heroku-api/src/main/java/com/heroku/api/exception/HerokuAPIException.java // public class HerokuAPIException extends RuntimeException { // // // public HerokuAPIException(String msg) { // super(msg); // } // // public HerokuAPIException(Throwable throwable) { // super(throwable); // } // // public HerokuAPIException(String msg, Throwable throwable) { // super(msg, throwable); // } // // // } // // Path: heroku-api/src/main/java/com/heroku/api/http/Http.java // public class Http { // /** // * HTTP Accept header model. // */ // public static enum Accept implements Header { // JSON("application/json"), // TEXT("text/plain"); // // private String value; // static String ACCEPT = "Accept"; // // Accept(String val) { // this.value = val; // } // // @Override // public String getHeaderName() { // return ACCEPT; // } // // @Override // public String getHeaderValue() { // return value; // } // // } // // /** // * HTTP Content-Type header model. // */ // public static enum ContentType implements Header { // JSON("application/json"), // FORM_URLENCODED("application/x-www-form-urlencoded"), // SSH_AUTHKEY("text/ssh-authkey"); // // private String value; // static String CONTENT_TYPE = "Content-Type"; // // ContentType(String val) { // this.value = val; // } // // @Override // public String getHeaderName() { // return CONTENT_TYPE; // } // // @Override // public String getHeaderValue() { // return value; // } // // } // // /** // * HTTP User-Agent header model. // * // * @see UserAgentValueProvider // */ // public static enum UserAgent implements Header { // LATEST(loadValueProvider()); // // static final String USER_AGENT = "User-Agent"; // private final UserAgentValueProvider userAgentValueProvider; // // UserAgent(UserAgentValueProvider userAgentValueProvider) { // this.userAgentValueProvider = userAgentValueProvider; // } // // @Override // public String getHeaderName() { // return USER_AGENT; // } // // @Override // public String getHeaderValue() { // return userAgentValueProvider.getHeaderValue(); // } // // public String getHeaderValue(String customPart) { // return userAgentValueProvider.getHeaderValue(customPart); // } // // private static UserAgentValueProvider loadValueProvider() { // final Iterator<UserAgentValueProvider> customProviders = // ServiceLoader.load(UserAgentValueProvider.class, UserAgent.class.getClassLoader()).iterator(); // // if (customProviders.hasNext()) { // return customProviders.next(); // } else { // return new UserAgentValueProvider.DEFAULT(); // } // } // } // // /** // * Represent a name/value pair for a HTTP header. Not all are implemented. Only those used by the Heroku API. // */ // public static interface Header { // // public static class Util { // public static Map<String, String> setHeaders(Header... headers) { // Map<String, String> headerMap = new HashMap<String, String>(); // for (Header h : headers) { // headerMap.put(h.getHeaderName(), h.getHeaderValue()); // } // return headerMap; // } // } // // String getHeaderName(); // // String getHeaderValue(); // // } // // /** // * HTTP Methods. Not all are implemented. Only those used by the Heroku API. // */ // public static enum Method {GET, PUT, POST, DELETE, PATCH} // // /** // * HTTP Status codes. Not all are implemented. Only those used by the Heroku API. // */ // public static enum Status { // OK(200), CREATED(201), ACCEPTED(202), PAYMENT_REQUIRED(402), FORBIDDEN(403), NOT_FOUND(404), UNPROCESSABLE_ENTITY(422), INTERNAL_SERVER_ERROR(500), SERVICE_UNAVAILABLE(503); // // public final int statusCode; // // Status(int statusCode) { // this.statusCode = statusCode; // } // // public boolean equals(int code) { // return statusCode == code; // } // } // }
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import java.io.IOException; import java.io.InputStream; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.cert.X509Certificate; import java.util.HashMap; import java.util.Map; import java.util.Properties; import com.heroku.api.exception.HerokuAPIException; import com.heroku.api.http.Http;
Slug(Slugs.value + "/%s"), Sources("/sources"), Status(App.value + "/status"), Stacks("/stacks"), Domains(App.value + "/domains"), Domain(Domains.value + "/%s"), Dynos("/apps/%s/dynos"), Dyno(Dynos.value + "/%s"), Formations(App.value + "/formation"), Formation(Formations.value + "/%s"), BuildpackInstalltions("/apps/%s/buildpack-installations"), TeamApps("/teams/%s/apps"), TeamAppsAll("/teams/apps"), TeamApp("/teams/apps/%s"), Team("/teams/%s"), Teams("/teams"), TeamInvoices("/teams/%s/invoices"), TeamInvoice("/teams/%s/invoices/%s"),; public final String value; Resource(String value) { this.value = value; } public String format(String... values) { return String.format(value, values); } }
// Path: heroku-api/src/main/java/com/heroku/api/exception/HerokuAPIException.java // public class HerokuAPIException extends RuntimeException { // // // public HerokuAPIException(String msg) { // super(msg); // } // // public HerokuAPIException(Throwable throwable) { // super(throwable); // } // // public HerokuAPIException(String msg, Throwable throwable) { // super(msg, throwable); // } // // // } // // Path: heroku-api/src/main/java/com/heroku/api/http/Http.java // public class Http { // /** // * HTTP Accept header model. // */ // public static enum Accept implements Header { // JSON("application/json"), // TEXT("text/plain"); // // private String value; // static String ACCEPT = "Accept"; // // Accept(String val) { // this.value = val; // } // // @Override // public String getHeaderName() { // return ACCEPT; // } // // @Override // public String getHeaderValue() { // return value; // } // // } // // /** // * HTTP Content-Type header model. // */ // public static enum ContentType implements Header { // JSON("application/json"), // FORM_URLENCODED("application/x-www-form-urlencoded"), // SSH_AUTHKEY("text/ssh-authkey"); // // private String value; // static String CONTENT_TYPE = "Content-Type"; // // ContentType(String val) { // this.value = val; // } // // @Override // public String getHeaderName() { // return CONTENT_TYPE; // } // // @Override // public String getHeaderValue() { // return value; // } // // } // // /** // * HTTP User-Agent header model. // * // * @see UserAgentValueProvider // */ // public static enum UserAgent implements Header { // LATEST(loadValueProvider()); // // static final String USER_AGENT = "User-Agent"; // private final UserAgentValueProvider userAgentValueProvider; // // UserAgent(UserAgentValueProvider userAgentValueProvider) { // this.userAgentValueProvider = userAgentValueProvider; // } // // @Override // public String getHeaderName() { // return USER_AGENT; // } // // @Override // public String getHeaderValue() { // return userAgentValueProvider.getHeaderValue(); // } // // public String getHeaderValue(String customPart) { // return userAgentValueProvider.getHeaderValue(customPart); // } // // private static UserAgentValueProvider loadValueProvider() { // final Iterator<UserAgentValueProvider> customProviders = // ServiceLoader.load(UserAgentValueProvider.class, UserAgent.class.getClassLoader()).iterator(); // // if (customProviders.hasNext()) { // return customProviders.next(); // } else { // return new UserAgentValueProvider.DEFAULT(); // } // } // } // // /** // * Represent a name/value pair for a HTTP header. Not all are implemented. Only those used by the Heroku API. // */ // public static interface Header { // // public static class Util { // public static Map<String, String> setHeaders(Header... headers) { // Map<String, String> headerMap = new HashMap<String, String>(); // for (Header h : headers) { // headerMap.put(h.getHeaderName(), h.getHeaderValue()); // } // return headerMap; // } // } // // String getHeaderName(); // // String getHeaderValue(); // // } // // /** // * HTTP Methods. Not all are implemented. Only those used by the Heroku API. // */ // public static enum Method {GET, PUT, POST, DELETE, PATCH} // // /** // * HTTP Status codes. Not all are implemented. Only those used by the Heroku API. // */ // public static enum Status { // OK(200), CREATED(201), ACCEPTED(202), PAYMENT_REQUIRED(402), FORBIDDEN(403), NOT_FOUND(404), UNPROCESSABLE_ENTITY(422), INTERNAL_SERVER_ERROR(500), SERVICE_UNAVAILABLE(503); // // public final int statusCode; // // Status(int statusCode) { // this.statusCode = statusCode; // } // // public boolean equals(int code) { // return statusCode == code; // } // } // } // Path: heroku-api/src/main/java/com/heroku/api/Heroku.java import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import java.io.IOException; import java.io.InputStream; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.cert.X509Certificate; import java.util.HashMap; import java.util.Map; import java.util.Properties; import com.heroku.api.exception.HerokuAPIException; import com.heroku.api.http.Http; Slug(Slugs.value + "/%s"), Sources("/sources"), Status(App.value + "/status"), Stacks("/stacks"), Domains(App.value + "/domains"), Domain(Domains.value + "/%s"), Dynos("/apps/%s/dynos"), Dyno(Dynos.value + "/%s"), Formations(App.value + "/formation"), Formation(Formations.value + "/%s"), BuildpackInstalltions("/apps/%s/buildpack-installations"), TeamApps("/teams/%s/apps"), TeamAppsAll("/teams/apps"), TeamApp("/teams/apps/%s"), Team("/teams/%s"), Teams("/teams"), TeamInvoices("/teams/%s/invoices"), TeamInvoice("/teams/%s/invoices/%s"),; public final String value; Resource(String value) { this.value = value; } public String format(String... values) { return String.format(value, values); } }
public enum ApiVersion implements Http.Header {
mkindalov/struckture
src/test/java/org/struckture/base/StrucktureStruckTest.java
// Path: src/main/java/org/struckture/base/exceptions/FieldConfigurationException.java // public class FieldConfigurationException extends StruckException { // /** // * Constructor. // * @param message message // */ // public FieldConfigurationException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public FieldConfigurationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StrucktureReadException.java // public class StrucktureReadException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StrucktureReadException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public StrucktureReadException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StructureConfigurationException.java // public class StructureConfigurationException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StructureConfigurationException(String message) { // super(message); // } // }
import org.struckture.base.annotations.StruckField; import org.struckture.base.annotations.Struckture; import org.struckture.base.exceptions.FieldConfigurationException; import org.struckture.base.exceptions.StrucktureReadException; import org.struckture.base.exceptions.StructureConfigurationException; import org.junit.Test; import sun.reflect.generics.reflectiveObjects.NotImplementedException; import java.io.InputStream; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.junit.MatcherAssert.assertThat; import static org.junit.Assert.fail;
package org.struckture.base; /** * Test. */ public class StrucktureStruckTest extends StrucktureTest { @Struckture(length = 0x10) private static class StruckTestStructure { @StruckField(offset = 0, size = 2) private boolean[] array; private String string; } @Test public void shouldNotSetNotAnnotatedField() { //given InputStream stream = stream( o(0x7, 0, 0, 0x10, 0, 0, 0, 0), o(0x7, 0, 0, 0x5, 0, 0, 0, 0), o(0x20, 0, 0, 0, 0, 0, 0, 0), o(0x7, 0, 0x1, 0x5, 0, 0, 0, 0)); Struck<StruckTestStructure> struck = Strucktor.forClass(StruckTestStructure.class); //when StruckTestStructure structure = struck.read(stream); //then assertThat(structure.string, is(nullValue())); } @Struckture(length = 0x10) private static class NegativeOffsetTestStructure { @StruckField(offset = -1) private int integer; }
// Path: src/main/java/org/struckture/base/exceptions/FieldConfigurationException.java // public class FieldConfigurationException extends StruckException { // /** // * Constructor. // * @param message message // */ // public FieldConfigurationException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public FieldConfigurationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StrucktureReadException.java // public class StrucktureReadException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StrucktureReadException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public StrucktureReadException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StructureConfigurationException.java // public class StructureConfigurationException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StructureConfigurationException(String message) { // super(message); // } // } // Path: src/test/java/org/struckture/base/StrucktureStruckTest.java import org.struckture.base.annotations.StruckField; import org.struckture.base.annotations.Struckture; import org.struckture.base.exceptions.FieldConfigurationException; import org.struckture.base.exceptions.StrucktureReadException; import org.struckture.base.exceptions.StructureConfigurationException; import org.junit.Test; import sun.reflect.generics.reflectiveObjects.NotImplementedException; import java.io.InputStream; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.junit.MatcherAssert.assertThat; import static org.junit.Assert.fail; package org.struckture.base; /** * Test. */ public class StrucktureStruckTest extends StrucktureTest { @Struckture(length = 0x10) private static class StruckTestStructure { @StruckField(offset = 0, size = 2) private boolean[] array; private String string; } @Test public void shouldNotSetNotAnnotatedField() { //given InputStream stream = stream( o(0x7, 0, 0, 0x10, 0, 0, 0, 0), o(0x7, 0, 0, 0x5, 0, 0, 0, 0), o(0x20, 0, 0, 0, 0, 0, 0, 0), o(0x7, 0, 0x1, 0x5, 0, 0, 0, 0)); Struck<StruckTestStructure> struck = Strucktor.forClass(StruckTestStructure.class); //when StruckTestStructure structure = struck.read(stream); //then assertThat(structure.string, is(nullValue())); } @Struckture(length = 0x10) private static class NegativeOffsetTestStructure { @StruckField(offset = -1) private int integer; }
@Test(expected = FieldConfigurationException.class)
mkindalov/struckture
src/test/java/org/struckture/base/StrucktureStruckTest.java
// Path: src/main/java/org/struckture/base/exceptions/FieldConfigurationException.java // public class FieldConfigurationException extends StruckException { // /** // * Constructor. // * @param message message // */ // public FieldConfigurationException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public FieldConfigurationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StrucktureReadException.java // public class StrucktureReadException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StrucktureReadException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public StrucktureReadException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StructureConfigurationException.java // public class StructureConfigurationException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StructureConfigurationException(String message) { // super(message); // } // }
import org.struckture.base.annotations.StruckField; import org.struckture.base.annotations.Struckture; import org.struckture.base.exceptions.FieldConfigurationException; import org.struckture.base.exceptions.StrucktureReadException; import org.struckture.base.exceptions.StructureConfigurationException; import org.junit.Test; import sun.reflect.generics.reflectiveObjects.NotImplementedException; import java.io.InputStream; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.junit.MatcherAssert.assertThat; import static org.junit.Assert.fail;
//expect exception } @Struckture(length = 0x8, allowOverlapping = true) private static class OverlappingWithAllowTestStructure { @StruckField(offset = 4) private int integer; @StruckField(offset = 4, size = 4) private byte[] bytes; } @Test public void shouldAllowOverlappingFieldsWhenOverlappingEnabled() { //given //when Struck<OverlappingWithAllowTestStructure> structure = Strucktor.forClass(OverlappingWithAllowTestStructure.class); //then assertThat(structure, is(notNullValue())); } @Struckture(length = 0x8) private static class OverlappingTestStructure { @StruckField(offset = 4) private int integer; @StruckField(offset = 4, size = 4) private byte[] bytes; }
// Path: src/main/java/org/struckture/base/exceptions/FieldConfigurationException.java // public class FieldConfigurationException extends StruckException { // /** // * Constructor. // * @param message message // */ // public FieldConfigurationException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public FieldConfigurationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StrucktureReadException.java // public class StrucktureReadException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StrucktureReadException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public StrucktureReadException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StructureConfigurationException.java // public class StructureConfigurationException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StructureConfigurationException(String message) { // super(message); // } // } // Path: src/test/java/org/struckture/base/StrucktureStruckTest.java import org.struckture.base.annotations.StruckField; import org.struckture.base.annotations.Struckture; import org.struckture.base.exceptions.FieldConfigurationException; import org.struckture.base.exceptions.StrucktureReadException; import org.struckture.base.exceptions.StructureConfigurationException; import org.junit.Test; import sun.reflect.generics.reflectiveObjects.NotImplementedException; import java.io.InputStream; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.junit.MatcherAssert.assertThat; import static org.junit.Assert.fail; //expect exception } @Struckture(length = 0x8, allowOverlapping = true) private static class OverlappingWithAllowTestStructure { @StruckField(offset = 4) private int integer; @StruckField(offset = 4, size = 4) private byte[] bytes; } @Test public void shouldAllowOverlappingFieldsWhenOverlappingEnabled() { //given //when Struck<OverlappingWithAllowTestStructure> structure = Strucktor.forClass(OverlappingWithAllowTestStructure.class); //then assertThat(structure, is(notNullValue())); } @Struckture(length = 0x8) private static class OverlappingTestStructure { @StruckField(offset = 4) private int integer; @StruckField(offset = 4, size = 4) private byte[] bytes; }
@Test(expected = StructureConfigurationException.class)
mkindalov/struckture
src/test/java/org/struckture/base/StrucktureStruckTest.java
// Path: src/main/java/org/struckture/base/exceptions/FieldConfigurationException.java // public class FieldConfigurationException extends StruckException { // /** // * Constructor. // * @param message message // */ // public FieldConfigurationException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public FieldConfigurationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StrucktureReadException.java // public class StrucktureReadException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StrucktureReadException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public StrucktureReadException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StructureConfigurationException.java // public class StructureConfigurationException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StructureConfigurationException(String message) { // super(message); // } // }
import org.struckture.base.annotations.StruckField; import org.struckture.base.annotations.Struckture; import org.struckture.base.exceptions.FieldConfigurationException; import org.struckture.base.exceptions.StrucktureReadException; import org.struckture.base.exceptions.StructureConfigurationException; import org.junit.Test; import sun.reflect.generics.reflectiveObjects.NotImplementedException; import java.io.InputStream; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.junit.MatcherAssert.assertThat; import static org.junit.Assert.fail;
//expect exception } @Struckture(length = 0x8) private static class UnknownTypeFieldTestStructure { @StruckField(offset = 4) private Object object; } @Test(expected = FieldConfigurationException.class) public void shouldThrowExceptionWhenUnknownType() { //given //when Strucktor.forClass(UnknownTypeFieldTestStructure.class); //then //expect exception } @Struckture(length = 0x8) private static class BadConstructorStructure { @StruckField(offset = 4) private int integer; public BadConstructorStructure () { throw new NotImplementedException(); } }
// Path: src/main/java/org/struckture/base/exceptions/FieldConfigurationException.java // public class FieldConfigurationException extends StruckException { // /** // * Constructor. // * @param message message // */ // public FieldConfigurationException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public FieldConfigurationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StrucktureReadException.java // public class StrucktureReadException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StrucktureReadException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public StrucktureReadException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StructureConfigurationException.java // public class StructureConfigurationException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StructureConfigurationException(String message) { // super(message); // } // } // Path: src/test/java/org/struckture/base/StrucktureStruckTest.java import org.struckture.base.annotations.StruckField; import org.struckture.base.annotations.Struckture; import org.struckture.base.exceptions.FieldConfigurationException; import org.struckture.base.exceptions.StrucktureReadException; import org.struckture.base.exceptions.StructureConfigurationException; import org.junit.Test; import sun.reflect.generics.reflectiveObjects.NotImplementedException; import java.io.InputStream; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.junit.MatcherAssert.assertThat; import static org.junit.Assert.fail; //expect exception } @Struckture(length = 0x8) private static class UnknownTypeFieldTestStructure { @StruckField(offset = 4) private Object object; } @Test(expected = FieldConfigurationException.class) public void shouldThrowExceptionWhenUnknownType() { //given //when Strucktor.forClass(UnknownTypeFieldTestStructure.class); //then //expect exception } @Struckture(length = 0x8) private static class BadConstructorStructure { @StruckField(offset = 4) private int integer; public BadConstructorStructure () { throw new NotImplementedException(); } }
@Test(expected = StrucktureReadException.class)
mkindalov/struckture
src/main/java/org/struckture/handlers/StringHandler.java
// Path: src/main/java/org/struckture/base/exceptions/FieldConfigurationException.java // public class FieldConfigurationException extends StruckException { // /** // * Constructor. // * @param message message // */ // public FieldConfigurationException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public FieldConfigurationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StrucktureReadException.java // public class StrucktureReadException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StrucktureReadException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public StrucktureReadException(String message, Throwable cause) { // super(message, cause); // } // }
import org.struckture.base.annotations.StringEncoding; import org.struckture.base.annotations.StruckField; import org.struckture.base.exceptions.FieldConfigurationException; import org.struckture.base.exceptions.StrucktureReadException; import java.io.UnsupportedEncodingException; import java.lang.annotation.Annotation; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.Set;
package org.struckture.handlers; /** * String Handler. */ public class StringHandler extends AbstractHandler<String> { private int size = 0; private String encoding = "ASCII"; @Override public void init(Set<Annotation> annotations) { super.init(annotations); StruckField struckField = getAnnotation(StruckField.class); size = struckField.size(); StringEncoding stringEncoding = getAnnotation(StringEncoding.class); if (stringEncoding != null) { if (Charset.isSupported(stringEncoding.value())) { encoding = stringEncoding.value(); } else {
// Path: src/main/java/org/struckture/base/exceptions/FieldConfigurationException.java // public class FieldConfigurationException extends StruckException { // /** // * Constructor. // * @param message message // */ // public FieldConfigurationException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public FieldConfigurationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StrucktureReadException.java // public class StrucktureReadException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StrucktureReadException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public StrucktureReadException(String message, Throwable cause) { // super(message, cause); // } // } // Path: src/main/java/org/struckture/handlers/StringHandler.java import org.struckture.base.annotations.StringEncoding; import org.struckture.base.annotations.StruckField; import org.struckture.base.exceptions.FieldConfigurationException; import org.struckture.base.exceptions.StrucktureReadException; import java.io.UnsupportedEncodingException; import java.lang.annotation.Annotation; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.Set; package org.struckture.handlers; /** * String Handler. */ public class StringHandler extends AbstractHandler<String> { private int size = 0; private String encoding = "ASCII"; @Override public void init(Set<Annotation> annotations) { super.init(annotations); StruckField struckField = getAnnotation(StruckField.class); size = struckField.size(); StringEncoding stringEncoding = getAnnotation(StringEncoding.class); if (stringEncoding != null) { if (Charset.isSupported(stringEncoding.value())) { encoding = stringEncoding.value(); } else {
throw new FieldConfigurationException("Encoding '" + encoding + "' is not supported.");
mkindalov/struckture
src/main/java/org/struckture/handlers/StringHandler.java
// Path: src/main/java/org/struckture/base/exceptions/FieldConfigurationException.java // public class FieldConfigurationException extends StruckException { // /** // * Constructor. // * @param message message // */ // public FieldConfigurationException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public FieldConfigurationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StrucktureReadException.java // public class StrucktureReadException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StrucktureReadException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public StrucktureReadException(String message, Throwable cause) { // super(message, cause); // } // }
import org.struckture.base.annotations.StringEncoding; import org.struckture.base.annotations.StruckField; import org.struckture.base.exceptions.FieldConfigurationException; import org.struckture.base.exceptions.StrucktureReadException; import java.io.UnsupportedEncodingException; import java.lang.annotation.Annotation; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.Set;
package org.struckture.handlers; /** * String Handler. */ public class StringHandler extends AbstractHandler<String> { private int size = 0; private String encoding = "ASCII"; @Override public void init(Set<Annotation> annotations) { super.init(annotations); StruckField struckField = getAnnotation(StruckField.class); size = struckField.size(); StringEncoding stringEncoding = getAnnotation(StringEncoding.class); if (stringEncoding != null) { if (Charset.isSupported(stringEncoding.value())) { encoding = stringEncoding.value(); } else { throw new FieldConfigurationException("Encoding '" + encoding + "' is not supported."); } } } @Override public int getSize() { return size; } @Override public String getValue(byte[] data) { ByteBuffer byteBuffer = ByteBuffer.wrap(data, getOffset(), size); byte[] bytes = new byte[size]; byteBuffer.get(bytes); try { return new String(bytes, encoding); } catch (UnsupportedEncodingException e) {
// Path: src/main/java/org/struckture/base/exceptions/FieldConfigurationException.java // public class FieldConfigurationException extends StruckException { // /** // * Constructor. // * @param message message // */ // public FieldConfigurationException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public FieldConfigurationException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/org/struckture/base/exceptions/StrucktureReadException.java // public class StrucktureReadException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StrucktureReadException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public StrucktureReadException(String message, Throwable cause) { // super(message, cause); // } // } // Path: src/main/java/org/struckture/handlers/StringHandler.java import org.struckture.base.annotations.StringEncoding; import org.struckture.base.annotations.StruckField; import org.struckture.base.exceptions.FieldConfigurationException; import org.struckture.base.exceptions.StrucktureReadException; import java.io.UnsupportedEncodingException; import java.lang.annotation.Annotation; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.Set; package org.struckture.handlers; /** * String Handler. */ public class StringHandler extends AbstractHandler<String> { private int size = 0; private String encoding = "ASCII"; @Override public void init(Set<Annotation> annotations) { super.init(annotations); StruckField struckField = getAnnotation(StruckField.class); size = struckField.size(); StringEncoding stringEncoding = getAnnotation(StringEncoding.class); if (stringEncoding != null) { if (Charset.isSupported(stringEncoding.value())) { encoding = stringEncoding.value(); } else { throw new FieldConfigurationException("Encoding '" + encoding + "' is not supported."); } } } @Override public int getSize() { return size; } @Override public String getValue(byte[] data) { ByteBuffer byteBuffer = ByteBuffer.wrap(data, getOffset(), size); byte[] bytes = new byte[size]; byteBuffer.get(bytes); try { return new String(bytes, encoding); } catch (UnsupportedEncodingException e) {
throw new StrucktureReadException("Cannot create string.", e);
mkindalov/struckture
src/test/java/org/struckture/base/StruckReadTest.java
// Path: src/main/java/org/struckture/base/exceptions/StrucktureReadException.java // public class StrucktureReadException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StrucktureReadException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public StrucktureReadException(String message, Throwable cause) { // super(message, cause); // } // }
import org.struckture.base.annotations.StruckField; import org.struckture.base.annotations.Struckture; import org.struckture.base.exceptions.StrucktureReadException; import org.junit.Test; import java.io.InputStream; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue;
package org.struckture.base; /** * Test. */ public class StruckReadTest extends StrucktureTest { @Struckture(length = 0x10) private static class StruckTestStructure { @StruckField(offset = 7) private byte[] array; @StruckField(offset = 0) private Integer size; @StruckField(offset = 7) private int test2; } @Test public void shouldReadMoreStructuresFromStream() { //given InputStream stream = stream( o(0x7, 0, 0, 0x10, 0, 0, 0, 0), o(0x7, 0, 0, 0x5, 0, 0, 0, 0), o(0x20, 0, 0, 0x10, 0, 0, 0, 0), o(0x7, 0, 0, 0x5, 0, 0, 0, 0)); Struck<StruckTestStructure> struck = Strucktor.forClass(StruckTestStructure.class); //when struck.read(stream); struck.read(stream); //then //Yuppie no exception }
// Path: src/main/java/org/struckture/base/exceptions/StrucktureReadException.java // public class StrucktureReadException extends StruckException { // // /** // * Constructor. // * @param message message // */ // public StrucktureReadException(String message) { // super(message); // } // // /** // * Constructor. // * @param message message // * @param cause cause // */ // public StrucktureReadException(String message, Throwable cause) { // super(message, cause); // } // } // Path: src/test/java/org/struckture/base/StruckReadTest.java import org.struckture.base.annotations.StruckField; import org.struckture.base.annotations.Struckture; import org.struckture.base.exceptions.StrucktureReadException; import org.junit.Test; import java.io.InputStream; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; package org.struckture.base; /** * Test. */ public class StruckReadTest extends StrucktureTest { @Struckture(length = 0x10) private static class StruckTestStructure { @StruckField(offset = 7) private byte[] array; @StruckField(offset = 0) private Integer size; @StruckField(offset = 7) private int test2; } @Test public void shouldReadMoreStructuresFromStream() { //given InputStream stream = stream( o(0x7, 0, 0, 0x10, 0, 0, 0, 0), o(0x7, 0, 0, 0x5, 0, 0, 0, 0), o(0x20, 0, 0, 0x10, 0, 0, 0, 0), o(0x7, 0, 0, 0x5, 0, 0, 0, 0)); Struck<StruckTestStructure> struck = Strucktor.forClass(StruckTestStructure.class); //when struck.read(stream); struck.read(stream); //then //Yuppie no exception }
@Test(expected = StrucktureReadException.class)
datacleaner/metamodel_extras
dbase/src/main/java/org/xBaseJ/fields/NumField.java
// Path: dbase/src/main/java/org/xBaseJ/xBaseJException.java // public class xBaseJException extends Exception { // // private static final long serialVersionUID = 1L; // // public xBaseJException() { // super(); // } // // public xBaseJException(String s) { // super(s); // } // }
import java.io.IOException; import java.nio.ByteBuffer; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import org.xBaseJ.xBaseJException;
/** * eobjects.org MetaModel * Copyright (C) 2010 eobjects.org * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.xBaseJ.fields; /** * This class is courtesy of the xBaseJ project: http://xbasej.sourceforge.net/ * * Copyright 1997-2007 - American Coders, LTD - Raleigh NC USA * * <pre> * American Coders, Ltd * P. O. Box 97462 * Raleigh, NC 27615 USA * 1-919-846-2014 * http://www.americancoders.com * </pre> * * @author Joe McVerry, American Coders Ltd. */ public class NumField extends Field { private static final long serialVersionUID = 1L; private byte decPosition = 0; private static DecimalFormatSymbols dfs = new DecimalFormatSymbols(); private static char decimalSeparator = dfs.getDecimalSeparator(); public NumField() { super(); } public Object clone() throws CloneNotSupportedException { NumField tField = (NumField) super.clone(); tField.name = new String(name); tField.nength = nength; tField.decPosition = decPosition; return tField; } public NumField(String iName, int iLength, int idecPosition,
// Path: dbase/src/main/java/org/xBaseJ/xBaseJException.java // public class xBaseJException extends Exception { // // private static final long serialVersionUID = 1L; // // public xBaseJException() { // super(); // } // // public xBaseJException(String s) { // super(s); // } // } // Path: dbase/src/main/java/org/xBaseJ/fields/NumField.java import java.io.IOException; import java.nio.ByteBuffer; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import org.xBaseJ.xBaseJException; /** * eobjects.org MetaModel * Copyright (C) 2010 eobjects.org * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.xBaseJ.fields; /** * This class is courtesy of the xBaseJ project: http://xbasej.sourceforge.net/ * * Copyright 1997-2007 - American Coders, LTD - Raleigh NC USA * * <pre> * American Coders, Ltd * P. O. Box 97462 * Raleigh, NC 27615 USA * 1-919-846-2014 * http://www.americancoders.com * </pre> * * @author Joe McVerry, American Coders Ltd. */ public class NumField extends Field { private static final long serialVersionUID = 1L; private byte decPosition = 0; private static DecimalFormatSymbols dfs = new DecimalFormatSymbols(); private static char decimalSeparator = dfs.getDecimalSeparator(); public NumField() { super(); } public Object clone() throws CloneNotSupportedException { NumField tField = (NumField) super.clone(); tField.name = new String(name); tField.nength = nength; tField.decPosition = decPosition; return tField; } public NumField(String iName, int iLength, int idecPosition,
ByteBuffer inBuffer) throws xBaseJException {
datacleaner/metamodel_extras
dbase/src/main/java/org/xBaseJ/fields/FloatField.java
// Path: dbase/src/main/java/org/xBaseJ/xBaseJException.java // public class xBaseJException extends Exception { // // private static final long serialVersionUID = 1L; // // public xBaseJException() { // super(); // } // // public xBaseJException(String s) { // super(s); // } // }
import java.text.DecimalFormatSymbols; import org.xBaseJ.xBaseJException; import java.io.IOException; import java.nio.ByteBuffer;
/** * eobjects.org MetaModel * Copyright (C) 2010 eobjects.org * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.xBaseJ.fields; /** * This class is courtesy of the xBaseJ project: http://xbasej.sourceforge.net/ * * Copyright 1997-2007 - American Coders, LTD - Raleigh NC USA * * <pre> * American Coders, Ltd * P. O. Box 97462 * Raleigh, NC 27615 USA * 1-919-846-2014 * http://www.americancoders.com * </pre> * * @author Joe McVerry, American Coders Ltd. */ public class FloatField extends NumField { private static final long serialVersionUID = 1L; private byte decPosition = 0; private static char decimalSeparator = new DecimalFormatSymbols() .getDecimalSeparator(); public FloatField() { super(); } public FloatField(String iName, int iLength, int DecPoint,
// Path: dbase/src/main/java/org/xBaseJ/xBaseJException.java // public class xBaseJException extends Exception { // // private static final long serialVersionUID = 1L; // // public xBaseJException() { // super(); // } // // public xBaseJException(String s) { // super(s); // } // } // Path: dbase/src/main/java/org/xBaseJ/fields/FloatField.java import java.text.DecimalFormatSymbols; import org.xBaseJ.xBaseJException; import java.io.IOException; import java.nio.ByteBuffer; /** * eobjects.org MetaModel * Copyright (C) 2010 eobjects.org * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.xBaseJ.fields; /** * This class is courtesy of the xBaseJ project: http://xbasej.sourceforge.net/ * * Copyright 1997-2007 - American Coders, LTD - Raleigh NC USA * * <pre> * American Coders, Ltd * P. O. Box 97462 * Raleigh, NC 27615 USA * 1-919-846-2014 * http://www.americancoders.com * </pre> * * @author Joe McVerry, American Coders Ltd. */ public class FloatField extends NumField { private static final long serialVersionUID = 1L; private byte decPosition = 0; private static char decimalSeparator = new DecimalFormatSymbols() .getDecimalSeparator(); public FloatField() { super(); } public FloatField(String iName, int iLength, int DecPoint,
ByteBuffer inBuffer) throws xBaseJException {
datacleaner/metamodel_extras
dbase/src/main/java/org/xBaseJ/fields/CharField.java
// Path: dbase/src/main/java/org/xBaseJ/xBaseJException.java // public class xBaseJException extends Exception { // // private static final long serialVersionUID = 1L; // // public xBaseJException() { // super(); // } // // public xBaseJException(String s) { // super(s); // } // }
import org.xBaseJ.xBaseJException; import java.io.IOException; import java.nio.ByteBuffer;
/** * eobjects.org MetaModel * Copyright (C) 2010 eobjects.org * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.xBaseJ.fields; /** * This class is courtesy of the xBaseJ project: http://xbasej.sourceforge.net/ * * Copyright 1997-2007 - American Coders, LTD - Raleigh NC USA * * <pre> * American Coders, Ltd * P. O. Box 97462 * Raleigh, NC 27615 USA * 1-919-846-2014 * http://www.americancoders.com * </pre> * * @author Joe McVerry, American Coders Ltd. */ public class CharField extends Field { private static final long serialVersionUID = 1L; public Object clone() throws CloneNotSupportedException { CharField tField = (CharField) super.clone(); tField.name = new String(name); tField.nength = nength; return tField; } public CharField() { super(); } public CharField(String iName, int iLength, ByteBuffer inBuffer)
// Path: dbase/src/main/java/org/xBaseJ/xBaseJException.java // public class xBaseJException extends Exception { // // private static final long serialVersionUID = 1L; // // public xBaseJException() { // super(); // } // // public xBaseJException(String s) { // super(s); // } // } // Path: dbase/src/main/java/org/xBaseJ/fields/CharField.java import org.xBaseJ.xBaseJException; import java.io.IOException; import java.nio.ByteBuffer; /** * eobjects.org MetaModel * Copyright (C) 2010 eobjects.org * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.xBaseJ.fields; /** * This class is courtesy of the xBaseJ project: http://xbasej.sourceforge.net/ * * Copyright 1997-2007 - American Coders, LTD - Raleigh NC USA * * <pre> * American Coders, Ltd * P. O. Box 97462 * Raleigh, NC 27615 USA * 1-919-846-2014 * http://www.americancoders.com * </pre> * * @author Joe McVerry, American Coders Ltd. */ public class CharField extends Field { private static final long serialVersionUID = 1L; public Object clone() throws CloneNotSupportedException { CharField tField = (CharField) super.clone(); tField.name = new String(name); tField.nength = nength; return tField; } public CharField() { super(); } public CharField(String iName, int iLength, ByteBuffer inBuffer)
throws xBaseJException, IOException {
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/Point.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Point { private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; private final byte[] point; public Point() { this.point = HEX.decode(STANDARD_GROUP_ELEMENT); } public Point(byte[] point) { this.point = point; }
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/crypto/Point.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Point { private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; private final byte[] point; public Point() { this.point = HEX.decode(STANDARD_GROUP_ELEMENT); } public Point(byte[] point) { this.point = point; }
public Point(String point, Encoder encoder) {
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/Point.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Point { private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; private final byte[] point; public Point() { this.point = HEX.decode(STANDARD_GROUP_ELEMENT); } public Point(byte[] point) { this.point = point; } public Point(String point, Encoder encoder) { this(encoder.decode(point)); } public Point mult(byte[] n) {
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/crypto/Point.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Point { private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; private final byte[] point; public Point() { this.point = HEX.decode(STANDARD_GROUP_ELEMENT); } public Point(byte[] point) { this.point = point; } public Point(String point, Encoder encoder) { this(encoder.decode(point)); } public Point mult(byte[] n) {
byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES);
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/Point.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Point { private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; private final byte[] point; public Point() { this.point = HEX.decode(STANDARD_GROUP_ELEMENT); } public Point(byte[] point) { this.point = point; } public Point(String point, Encoder encoder) { this(encoder.decode(point)); } public Point mult(byte[] n) { byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES);
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/crypto/Point.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Point { private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; private final byte[] point; public Point() { this.point = HEX.decode(STANDARD_GROUP_ELEMENT); } public Point(byte[] point) { this.point = point; } public Point(String point, Encoder encoder) { this(encoder.decode(point)); } public Point mult(byte[] n) { byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES);
sodium().crypto_scalarmult_curve25519(result, n, point);
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/KeyPair.java
// Path: src/main/java/org/abstractj/kalium/crypto/Point.java // public class Point { // // private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; // // private final byte[] point; // // public Point() { // this.point = HEX.decode(STANDARD_GROUP_ELEMENT); // } // // public Point(byte[] point) { // this.point = point; // } // // public Point(String point, Encoder encoder) { // this(encoder.decode(point)); // } // // public Point mult(byte[] n) { // byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES); // sodium().crypto_scalarmult_curve25519(result, n, point); // return new Point(result); // } // // public Point mult(String n, Encoder encoder) { // return mult(encoder.decode(n)); // } // // @Override // public String toString() { // return HEX.encode(point); // } // // public byte[] toBytes() { // return point; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import org.abstractj.kalium.crypto.Point; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.zeros;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class KeyPair { private final byte[] publicKey; private final byte[] secretKey; public KeyPair() {
// Path: src/main/java/org/abstractj/kalium/crypto/Point.java // public class Point { // // private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; // // private final byte[] point; // // public Point() { // this.point = HEX.decode(STANDARD_GROUP_ELEMENT); // } // // public Point(byte[] point) { // this.point = point; // } // // public Point(String point, Encoder encoder) { // this(encoder.decode(point)); // } // // public Point mult(byte[] n) { // byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES); // sodium().crypto_scalarmult_curve25519(result, n, point); // return new Point(result); // } // // public Point mult(String n, Encoder encoder) { // return mult(encoder.decode(n)); // } // // @Override // public String toString() { // return HEX.encode(point); // } // // public byte[] toBytes() { // return point; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/keys/KeyPair.java import org.abstractj.kalium.crypto.Point; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.zeros; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class KeyPair { private final byte[] publicKey; private final byte[] secretKey; public KeyPair() {
this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES);
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/KeyPair.java
// Path: src/main/java/org/abstractj/kalium/crypto/Point.java // public class Point { // // private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; // // private final byte[] point; // // public Point() { // this.point = HEX.decode(STANDARD_GROUP_ELEMENT); // } // // public Point(byte[] point) { // this.point = point; // } // // public Point(String point, Encoder encoder) { // this(encoder.decode(point)); // } // // public Point mult(byte[] n) { // byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES); // sodium().crypto_scalarmult_curve25519(result, n, point); // return new Point(result); // } // // public Point mult(String n, Encoder encoder) { // return mult(encoder.decode(n)); // } // // @Override // public String toString() { // return HEX.encode(point); // } // // public byte[] toBytes() { // return point; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import org.abstractj.kalium.crypto.Point; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.zeros;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class KeyPair { private final byte[] publicKey; private final byte[] secretKey; public KeyPair() { this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES);
// Path: src/main/java/org/abstractj/kalium/crypto/Point.java // public class Point { // // private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; // // private final byte[] point; // // public Point() { // this.point = HEX.decode(STANDARD_GROUP_ELEMENT); // } // // public Point(byte[] point) { // this.point = point; // } // // public Point(String point, Encoder encoder) { // this(encoder.decode(point)); // } // // public Point mult(byte[] n) { // byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES); // sodium().crypto_scalarmult_curve25519(result, n, point); // return new Point(result); // } // // public Point mult(String n, Encoder encoder) { // return mult(encoder.decode(n)); // } // // @Override // public String toString() { // return HEX.encode(point); // } // // public byte[] toBytes() { // return point; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/keys/KeyPair.java import org.abstractj.kalium.crypto.Point; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.zeros; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class KeyPair { private final byte[] publicKey; private final byte[] secretKey; public KeyPair() { this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES);
sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey);
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/KeyPair.java
// Path: src/main/java/org/abstractj/kalium/crypto/Point.java // public class Point { // // private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; // // private final byte[] point; // // public Point() { // this.point = HEX.decode(STANDARD_GROUP_ELEMENT); // } // // public Point(byte[] point) { // this.point = point; // } // // public Point(String point, Encoder encoder) { // this(encoder.decode(point)); // } // // public Point mult(byte[] n) { // byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES); // sodium().crypto_scalarmult_curve25519(result, n, point); // return new Point(result); // } // // public Point mult(String n, Encoder encoder) { // return mult(encoder.decode(n)); // } // // @Override // public String toString() { // return HEX.encode(point); // } // // public byte[] toBytes() { // return point; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import org.abstractj.kalium.crypto.Point; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.zeros;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class KeyPair { private final byte[] publicKey; private final byte[] secretKey; public KeyPair() { this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); } public KeyPair(byte[] secretKey) { this.secretKey = secretKey;
// Path: src/main/java/org/abstractj/kalium/crypto/Point.java // public class Point { // // private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; // // private final byte[] point; // // public Point() { // this.point = HEX.decode(STANDARD_GROUP_ELEMENT); // } // // public Point(byte[] point) { // this.point = point; // } // // public Point(String point, Encoder encoder) { // this(encoder.decode(point)); // } // // public Point mult(byte[] n) { // byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES); // sodium().crypto_scalarmult_curve25519(result, n, point); // return new Point(result); // } // // public Point mult(String n, Encoder encoder) { // return mult(encoder.decode(n)); // } // // @Override // public String toString() { // return HEX.encode(point); // } // // public byte[] toBytes() { // return point; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/keys/KeyPair.java import org.abstractj.kalium.crypto.Point; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.zeros; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class KeyPair { private final byte[] publicKey; private final byte[] secretKey; public KeyPair() { this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); } public KeyPair(byte[] secretKey) { this.secretKey = secretKey;
checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES);
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/KeyPair.java
// Path: src/main/java/org/abstractj/kalium/crypto/Point.java // public class Point { // // private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; // // private final byte[] point; // // public Point() { // this.point = HEX.decode(STANDARD_GROUP_ELEMENT); // } // // public Point(byte[] point) { // this.point = point; // } // // public Point(String point, Encoder encoder) { // this(encoder.decode(point)); // } // // public Point mult(byte[] n) { // byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES); // sodium().crypto_scalarmult_curve25519(result, n, point); // return new Point(result); // } // // public Point mult(String n, Encoder encoder) { // return mult(encoder.decode(n)); // } // // @Override // public String toString() { // return HEX.encode(point); // } // // public byte[] toBytes() { // return point; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import org.abstractj.kalium.crypto.Point; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.zeros;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class KeyPair { private final byte[] publicKey; private final byte[] secretKey; public KeyPair() { this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); } public KeyPair(byte[] secretKey) { this.secretKey = secretKey; checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES);
// Path: src/main/java/org/abstractj/kalium/crypto/Point.java // public class Point { // // private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; // // private final byte[] point; // // public Point() { // this.point = HEX.decode(STANDARD_GROUP_ELEMENT); // } // // public Point(byte[] point) { // this.point = point; // } // // public Point(String point, Encoder encoder) { // this(encoder.decode(point)); // } // // public Point mult(byte[] n) { // byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES); // sodium().crypto_scalarmult_curve25519(result, n, point); // return new Point(result); // } // // public Point mult(String n, Encoder encoder) { // return mult(encoder.decode(n)); // } // // @Override // public String toString() { // return HEX.encode(point); // } // // public byte[] toBytes() { // return point; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/keys/KeyPair.java import org.abstractj.kalium.crypto.Point; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.zeros; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class KeyPair { private final byte[] publicKey; private final byte[] secretKey; public KeyPair() { this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); } public KeyPair(byte[] secretKey) { this.secretKey = secretKey; checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES);
Point point = new Point();
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/KeyPair.java
// Path: src/main/java/org/abstractj/kalium/crypto/Point.java // public class Point { // // private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; // // private final byte[] point; // // public Point() { // this.point = HEX.decode(STANDARD_GROUP_ELEMENT); // } // // public Point(byte[] point) { // this.point = point; // } // // public Point(String point, Encoder encoder) { // this(encoder.decode(point)); // } // // public Point mult(byte[] n) { // byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES); // sodium().crypto_scalarmult_curve25519(result, n, point); // return new Point(result); // } // // public Point mult(String n, Encoder encoder) { // return mult(encoder.decode(n)); // } // // @Override // public String toString() { // return HEX.encode(point); // } // // public byte[] toBytes() { // return point; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import org.abstractj.kalium.crypto.Point; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.zeros;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class KeyPair { private final byte[] publicKey; private final byte[] secretKey; public KeyPair() { this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); } public KeyPair(byte[] secretKey) { this.secretKey = secretKey; checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); Point point = new Point(); this.publicKey = point.mult(secretKey).toBytes(); }
// Path: src/main/java/org/abstractj/kalium/crypto/Point.java // public class Point { // // private static final String STANDARD_GROUP_ELEMENT = "0900000000000000000000000000000000000000000000000000000000000000"; // // private final byte[] point; // // public Point() { // this.point = HEX.decode(STANDARD_GROUP_ELEMENT); // } // // public Point(byte[] point) { // this.point = point; // } // // public Point(String point, Encoder encoder) { // this(encoder.decode(point)); // } // // public Point mult(byte[] n) { // byte[] result = zeros(CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES); // sodium().crypto_scalarmult_curve25519(result, n, point); // return new Point(result); // } // // public Point mult(String n, Encoder encoder) { // return mult(encoder.decode(n)); // } // // @Override // public String toString() { // return HEX.encode(point); // } // // public byte[] toBytes() { // return point; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/keys/KeyPair.java import org.abstractj.kalium.crypto.Point; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.zeros; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class KeyPair { private final byte[] publicKey; private final byte[] secretKey; public KeyPair() { this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); } public KeyPair(byte[] secretKey) { this.secretKey = secretKey; checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); Point point = new Point(); this.publicKey = point.mult(secretKey).toBytes(); }
public KeyPair(String secretKey, Encoder encoder) {
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/SealedBoxTest.java
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/keys/KeyPair.java // public class KeyPair { // // private final byte[] publicKey; // private final byte[] secretKey; // // public KeyPair() { // this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // this.publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); // sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); // } // // public KeyPair(byte[] secretKey) { // this.secretKey = secretKey; // checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // Point point = new Point(); // this.publicKey = point.mult(secretKey).toBytes(); // } // // public KeyPair(String secretKey, Encoder encoder) { // this(encoder.decode(secretKey)); // } // // public PublicKey getPublicKey() { // return new PublicKey(publicKey); // } // // public PrivateKey getPrivateKey() { // return new PrivateKey(secretKey); // } // }
import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.junit.Assert.assertArrayEquals; import java.security.SecureRandom; import org.abstractj.kalium.keys.KeyPair; import org.junit.Test;
package org.abstractj.kalium.crypto; public class SealedBoxTest { @Test public void testEncryptDecrypt() throws Exception { SecureRandom r = new SecureRandom();
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/keys/KeyPair.java // public class KeyPair { // // private final byte[] publicKey; // private final byte[] secretKey; // // public KeyPair() { // this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // this.publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); // sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); // } // // public KeyPair(byte[] secretKey) { // this.secretKey = secretKey; // checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // Point point = new Point(); // this.publicKey = point.mult(secretKey).toBytes(); // } // // public KeyPair(String secretKey, Encoder encoder) { // this(encoder.decode(secretKey)); // } // // public PublicKey getPublicKey() { // return new PublicKey(publicKey); // } // // public PrivateKey getPrivateKey() { // return new PrivateKey(secretKey); // } // } // Path: src/test/java/org/abstractj/kalium/crypto/SealedBoxTest.java import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.junit.Assert.assertArrayEquals; import java.security.SecureRandom; import org.abstractj.kalium.keys.KeyPair; import org.junit.Test; package org.abstractj.kalium.crypto; public class SealedBoxTest { @Test public void testEncryptDecrypt() throws Exception { SecureRandom r = new SecureRandom();
KeyPair keyPair = new KeyPair(new byte[CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES]);
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/SealedBoxTest.java
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/keys/KeyPair.java // public class KeyPair { // // private final byte[] publicKey; // private final byte[] secretKey; // // public KeyPair() { // this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // this.publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); // sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); // } // // public KeyPair(byte[] secretKey) { // this.secretKey = secretKey; // checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // Point point = new Point(); // this.publicKey = point.mult(secretKey).toBytes(); // } // // public KeyPair(String secretKey, Encoder encoder) { // this(encoder.decode(secretKey)); // } // // public PublicKey getPublicKey() { // return new PublicKey(publicKey); // } // // public PrivateKey getPrivateKey() { // return new PrivateKey(secretKey); // } // }
import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.junit.Assert.assertArrayEquals; import java.security.SecureRandom; import org.abstractj.kalium.keys.KeyPair; import org.junit.Test;
package org.abstractj.kalium.crypto; public class SealedBoxTest { @Test public void testEncryptDecrypt() throws Exception { SecureRandom r = new SecureRandom(); KeyPair keyPair = new KeyPair(new byte[CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES]); byte[] sk = keyPair.getPrivateKey().toBytes(); byte[] pk = keyPair.getPublicKey().toBytes(); byte[] m = new byte[r.nextInt(1000)]; r.nextBytes(m); SealedBox sb = new SealedBox(pk); byte[] c = sb.encrypt(m); SealedBox sb2 = new SealedBox(pk, sk); byte[] m2 = sb2.decrypt(c); assertArrayEquals(m, m2); } @Test public void testEncryptDecryptMultPublicKeys() throws Exception { SecureRandom r = new SecureRandom(); KeyPair keyPair = new KeyPair(new byte[CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES]); byte[] sk = keyPair.getPrivateKey().toBytes(); byte[] pk1 = keyPair.getPublicKey().toBytes(); byte[] pk2 = new byte[pk1.length];
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/keys/KeyPair.java // public class KeyPair { // // private final byte[] publicKey; // private final byte[] secretKey; // // public KeyPair() { // this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // this.publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); // sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); // } // // public KeyPair(byte[] secretKey) { // this.secretKey = secretKey; // checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // Point point = new Point(); // this.publicKey = point.mult(secretKey).toBytes(); // } // // public KeyPair(String secretKey, Encoder encoder) { // this(encoder.decode(secretKey)); // } // // public PublicKey getPublicKey() { // return new PublicKey(publicKey); // } // // public PrivateKey getPrivateKey() { // return new PrivateKey(secretKey); // } // } // Path: src/test/java/org/abstractj/kalium/crypto/SealedBoxTest.java import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.junit.Assert.assertArrayEquals; import java.security.SecureRandom; import org.abstractj.kalium.keys.KeyPair; import org.junit.Test; package org.abstractj.kalium.crypto; public class SealedBoxTest { @Test public void testEncryptDecrypt() throws Exception { SecureRandom r = new SecureRandom(); KeyPair keyPair = new KeyPair(new byte[CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES]); byte[] sk = keyPair.getPrivateKey().toBytes(); byte[] pk = keyPair.getPublicKey().toBytes(); byte[] m = new byte[r.nextInt(1000)]; r.nextBytes(m); SealedBox sb = new SealedBox(pk); byte[] c = sb.encrypt(m); SealedBox sb2 = new SealedBox(pk, sk); byte[] m2 = sb2.decrypt(c); assertArrayEquals(m, m2); } @Test public void testEncryptDecryptMultPublicKeys() throws Exception { SecureRandom r = new SecureRandom(); KeyPair keyPair = new KeyPair(new byte[CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES]); byte[] sk = keyPair.getPrivateKey().toBytes(); byte[] pk1 = keyPair.getPublicKey().toBytes(); byte[] pk2 = new byte[pk1.length];
sodium().crypto_scalarmult_base(pk2, sk);
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/Hash.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_GENERICHASH_BLAKE2B_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_HASH_SHA256_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_HASH_SHA512_BYTES; import static org.abstractj.kalium.NaCl.sodium;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Hash { public byte[] sha256(byte[] message) { byte[] buffer = new byte[CRYPTO_HASH_SHA256_BYTES];
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // Path: src/main/java/org/abstractj/kalium/crypto/Hash.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_GENERICHASH_BLAKE2B_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_HASH_SHA256_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_HASH_SHA512_BYTES; import static org.abstractj.kalium.NaCl.sodium; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Hash { public byte[] sha256(byte[] message) { byte[] buffer = new byte[CRYPTO_HASH_SHA256_BYTES];
sodium().crypto_hash_sha256(buffer, message, message.length);
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/Hash.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_GENERICHASH_BLAKE2B_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_HASH_SHA256_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_HASH_SHA512_BYTES; import static org.abstractj.kalium.NaCl.sodium;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Hash { public byte[] sha256(byte[] message) { byte[] buffer = new byte[CRYPTO_HASH_SHA256_BYTES]; sodium().crypto_hash_sha256(buffer, message, message.length); return buffer; } public byte[] sha512(byte[] message) { byte[] buffer = new byte[CRYPTO_HASH_SHA512_BYTES]; sodium().crypto_hash_sha512(buffer, message, message.length); return buffer; }
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // Path: src/main/java/org/abstractj/kalium/crypto/Hash.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_GENERICHASH_BLAKE2B_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_HASH_SHA256_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_HASH_SHA512_BYTES; import static org.abstractj.kalium.NaCl.sodium; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Hash { public byte[] sha256(byte[] message) { byte[] buffer = new byte[CRYPTO_HASH_SHA256_BYTES]; sodium().crypto_hash_sha256(buffer, message, message.length); return buffer; } public byte[] sha512(byte[] message) { byte[] buffer = new byte[CRYPTO_HASH_SHA512_BYTES]; sodium().crypto_hash_sha512(buffer, message, message.length); return buffer; }
public String sha256(String message, Encoder encoder) {
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/SecretBox.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.removeZeros;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class SecretBox { private byte[] key; public SecretBox(byte[] key) { this.key = key;
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // Path: src/main/java/org/abstractj/kalium/crypto/SecretBox.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.removeZeros; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class SecretBox { private byte[] key; public SecretBox(byte[] key) { this.key = key;
checkLength(key, CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES);
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/SecretBox.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.removeZeros;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class SecretBox { private byte[] key; public SecretBox(byte[] key) { this.key = key; checkLength(key, CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES); }
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // Path: src/main/java/org/abstractj/kalium/crypto/SecretBox.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.removeZeros; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class SecretBox { private byte[] key; public SecretBox(byte[] key) { this.key = key; checkLength(key, CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES); }
public SecretBox(String key, Encoder encoder) {
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/SecretBox.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.removeZeros;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class SecretBox { private byte[] key; public SecretBox(byte[] key) { this.key = key; checkLength(key, CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES); } public SecretBox(String key, Encoder encoder) { this(encoder.decode(key)); } public byte[] encrypt(byte[] nonce, byte[] message) { checkLength(nonce, CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES); byte[] msg = Util.prependZeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES, message); byte[] ct = Util.zeros(msg.length);
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // Path: src/main/java/org/abstractj/kalium/crypto/SecretBox.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.removeZeros; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class SecretBox { private byte[] key; public SecretBox(byte[] key) { this.key = key; checkLength(key, CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES); } public SecretBox(String key, Encoder encoder) { this(encoder.decode(key)); } public byte[] encrypt(byte[] nonce, byte[] message) { checkLength(nonce, CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES); byte[] msg = Util.prependZeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES, message); byte[] ct = Util.zeros(msg.length);
isValid(sodium().crypto_secretbox_xsalsa20poly1305(ct, msg, msg.length,
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/SecretBox.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.removeZeros;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class SecretBox { private byte[] key; public SecretBox(byte[] key) { this.key = key; checkLength(key, CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES); } public SecretBox(String key, Encoder encoder) { this(encoder.decode(key)); } public byte[] encrypt(byte[] nonce, byte[] message) { checkLength(nonce, CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES); byte[] msg = Util.prependZeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES, message); byte[] ct = Util.zeros(msg.length);
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // Path: src/main/java/org/abstractj/kalium/crypto/SecretBox.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.removeZeros; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class SecretBox { private byte[] key; public SecretBox(byte[] key) { this.key = key; checkLength(key, CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES); } public SecretBox(String key, Encoder encoder) { this(encoder.decode(key)); } public byte[] encrypt(byte[] nonce, byte[] message) { checkLength(nonce, CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES); byte[] msg = Util.prependZeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES, message); byte[] ct = Util.zeros(msg.length);
isValid(sodium().crypto_secretbox_xsalsa20poly1305(ct, msg, msg.length,
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/SecretBox.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.removeZeros;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class SecretBox { private byte[] key; public SecretBox(byte[] key) { this.key = key; checkLength(key, CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES); } public SecretBox(String key, Encoder encoder) { this(encoder.decode(key)); } public byte[] encrypt(byte[] nonce, byte[] message) { checkLength(nonce, CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES); byte[] msg = Util.prependZeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES, message); byte[] ct = Util.zeros(msg.length); isValid(sodium().crypto_secretbox_xsalsa20poly1305(ct, msg, msg.length, nonce, key), "Encryption failed");
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // Path: src/main/java/org/abstractj/kalium/crypto/SecretBox.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.removeZeros; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class SecretBox { private byte[] key; public SecretBox(byte[] key) { this.key = key; checkLength(key, CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES); } public SecretBox(String key, Encoder encoder) { this(encoder.decode(key)); } public byte[] encrypt(byte[] nonce, byte[] message) { checkLength(nonce, CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES); byte[] msg = Util.prependZeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES, message); byte[] ct = Util.zeros(msg.length); isValid(sodium().crypto_secretbox_xsalsa20poly1305(ct, msg, msg.length, nonce, key), "Encryption failed");
return removeZeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES, ct);
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/ShortHashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_KEY = "000102030405060708090a0b0c0d0e0f"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_MESSAGE = "000102030405060708090a0b0c0d0e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST = "e545be4961ca29a1"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST_EMPTY_STRING = "310e0edd47db6f72";
import org.junit.Test; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_KEY; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST_EMPTY_STRING; import static org.junit.Assert.assertEquals;
/** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHashTest { private final ShortHash hash = new ShortHash(); @Test public void testSiphash24() throws Exception {
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_KEY = "000102030405060708090a0b0c0d0e0f"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_MESSAGE = "000102030405060708090a0b0c0d0e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST = "e545be4961ca29a1"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST_EMPTY_STRING = "310e0edd47db6f72"; // Path: src/test/java/org/abstractj/kalium/crypto/ShortHashTest.java import org.junit.Test; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_KEY; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST_EMPTY_STRING; import static org.junit.Assert.assertEquals; /** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHashTest { private final ShortHash hash = new ShortHash(); @Test public void testSiphash24() throws Exception {
byte[] message = HEX.decode(SIPHASH24_MESSAGE);
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/ShortHashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_KEY = "000102030405060708090a0b0c0d0e0f"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_MESSAGE = "000102030405060708090a0b0c0d0e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST = "e545be4961ca29a1"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST_EMPTY_STRING = "310e0edd47db6f72";
import org.junit.Test; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_KEY; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST_EMPTY_STRING; import static org.junit.Assert.assertEquals;
/** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHashTest { private final ShortHash hash = new ShortHash(); @Test public void testSiphash24() throws Exception { byte[] message = HEX.decode(SIPHASH24_MESSAGE);
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_KEY = "000102030405060708090a0b0c0d0e0f"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_MESSAGE = "000102030405060708090a0b0c0d0e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST = "e545be4961ca29a1"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST_EMPTY_STRING = "310e0edd47db6f72"; // Path: src/test/java/org/abstractj/kalium/crypto/ShortHashTest.java import org.junit.Test; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_KEY; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST_EMPTY_STRING; import static org.junit.Assert.assertEquals; /** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHashTest { private final ShortHash hash = new ShortHash(); @Test public void testSiphash24() throws Exception { byte[] message = HEX.decode(SIPHASH24_MESSAGE);
byte[] key = HEX.decode(SIPHASH24_KEY);
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/ShortHashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_KEY = "000102030405060708090a0b0c0d0e0f"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_MESSAGE = "000102030405060708090a0b0c0d0e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST = "e545be4961ca29a1"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST_EMPTY_STRING = "310e0edd47db6f72";
import org.junit.Test; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_KEY; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST_EMPTY_STRING; import static org.junit.Assert.assertEquals;
/** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHashTest { private final ShortHash hash = new ShortHash(); @Test public void testSiphash24() throws Exception { byte[] message = HEX.decode(SIPHASH24_MESSAGE); byte[] key = HEX.decode(SIPHASH24_KEY); String result = HEX.encode(hash.siphash24(message, key));
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_KEY = "000102030405060708090a0b0c0d0e0f"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_MESSAGE = "000102030405060708090a0b0c0d0e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST = "e545be4961ca29a1"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST_EMPTY_STRING = "310e0edd47db6f72"; // Path: src/test/java/org/abstractj/kalium/crypto/ShortHashTest.java import org.junit.Test; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_KEY; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST_EMPTY_STRING; import static org.junit.Assert.assertEquals; /** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHashTest { private final ShortHash hash = new ShortHash(); @Test public void testSiphash24() throws Exception { byte[] message = HEX.decode(SIPHASH24_MESSAGE); byte[] key = HEX.decode(SIPHASH24_KEY); String result = HEX.encode(hash.siphash24(message, key));
assertEquals("Hash is invalid", SIPHASH24_DIGEST, result);
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/ShortHashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_KEY = "000102030405060708090a0b0c0d0e0f"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_MESSAGE = "000102030405060708090a0b0c0d0e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST = "e545be4961ca29a1"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST_EMPTY_STRING = "310e0edd47db6f72";
import org.junit.Test; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_KEY; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST_EMPTY_STRING; import static org.junit.Assert.assertEquals;
/** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHashTest { private final ShortHash hash = new ShortHash(); @Test public void testSiphash24() throws Exception { byte[] message = HEX.decode(SIPHASH24_MESSAGE); byte[] key = HEX.decode(SIPHASH24_KEY); String result = HEX.encode(hash.siphash24(message, key)); assertEquals("Hash is invalid", SIPHASH24_DIGEST, result); } @Test public void testSiphash24EmptyString() throws Exception { byte[] key = HEX.decode(SIPHASH24_KEY); String result = HEX.encode(hash.siphash24(new byte[0], key));
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_KEY = "000102030405060708090a0b0c0d0e0f"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_MESSAGE = "000102030405060708090a0b0c0d0e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST = "e545be4961ca29a1"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIPHASH24_DIGEST_EMPTY_STRING = "310e0edd47db6f72"; // Path: src/test/java/org/abstractj/kalium/crypto/ShortHashTest.java import org.junit.Test; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_KEY; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SIPHASH24_DIGEST_EMPTY_STRING; import static org.junit.Assert.assertEquals; /** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHashTest { private final ShortHash hash = new ShortHash(); @Test public void testSiphash24() throws Exception { byte[] message = HEX.decode(SIPHASH24_MESSAGE); byte[] key = HEX.decode(SIPHASH24_KEY); String result = HEX.encode(hash.siphash24(message, key)); assertEquals("Hash is invalid", SIPHASH24_DIGEST, result); } @Test public void testSiphash24EmptyString() throws Exception { byte[] key = HEX.decode(SIPHASH24_KEY); String result = HEX.encode(hash.siphash24(new byte[0], key));
assertEquals("Hash is invalid", SIPHASH24_DIGEST_EMPTY_STRING, result);
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/Advanced.java
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // }
import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_STREAM_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_STREAM_NONCEBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * <p/> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Advanced { public byte[] crypto_stream_xsalsa20_xor(byte[] message, byte[] nonce, byte[] key) {
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // Path: src/main/java/org/abstractj/kalium/crypto/Advanced.java import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_STREAM_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_STREAM_NONCEBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; /** * Copyright 2013 Bruno Oliveira, and individual contributors * <p/> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Advanced { public byte[] crypto_stream_xsalsa20_xor(byte[] message, byte[] nonce, byte[] key) {
checkLength(nonce, CRYPTO_STREAM_NONCEBYTES);
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/Advanced.java
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // }
import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_STREAM_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_STREAM_NONCEBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * <p/> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Advanced { public byte[] crypto_stream_xsalsa20_xor(byte[] message, byte[] nonce, byte[] key) { checkLength(nonce, CRYPTO_STREAM_NONCEBYTES); checkLength(key, CRYPTO_STREAM_KEYBYTES); byte[] buffer = new byte[message.length];
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // Path: src/main/java/org/abstractj/kalium/crypto/Advanced.java import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_STREAM_KEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_STREAM_NONCEBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; /** * Copyright 2013 Bruno Oliveira, and individual contributors * <p/> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Advanced { public byte[] crypto_stream_xsalsa20_xor(byte[] message, byte[] nonce, byte[] key) { checkLength(nonce, CRYPTO_STREAM_NONCEBYTES); checkLength(key, CRYPTO_STREAM_KEYBYTES); byte[] buffer = new byte[message.length];
sodium().crypto_stream_xor(buffer, message, message.length, nonce, key);
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/VerifyKey.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKey { private byte[] key; public VerifyKey(byte[] key) {
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/keys/VerifyKey.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKey { private byte[] key; public VerifyKey(byte[] key) {
checkLength(key, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES);
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/VerifyKey.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKey { private byte[] key; public VerifyKey(byte[] key) { checkLength(key, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); this.key = key; }
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/keys/VerifyKey.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKey { private byte[] key; public VerifyKey(byte[] key) { checkLength(key, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); this.key = key; }
public VerifyKey(String key, Encoder encoder) {
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/VerifyKey.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKey { private byte[] key; public VerifyKey(byte[] key) { checkLength(key, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); this.key = key; } public VerifyKey(String key, Encoder encoder) { this(encoder.decode(key)); } public boolean verify(byte[] message, byte[] signature) { checkLength(signature, CRYPTO_SIGN_ED25519_BYTES);
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/keys/VerifyKey.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKey { private byte[] key; public VerifyKey(byte[] key) { checkLength(key, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); this.key = key; } public VerifyKey(String key, Encoder encoder) { this(encoder.decode(key)); } public boolean verify(byte[] message, byte[] signature) { checkLength(signature, CRYPTO_SIGN_ED25519_BYTES);
return isValid(sodium().crypto_sign_ed25519_verify_detached(signature, message, message.length, key), "signature was forged or corrupted");
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/VerifyKey.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKey { private byte[] key; public VerifyKey(byte[] key) { checkLength(key, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); this.key = key; } public VerifyKey(String key, Encoder encoder) { this(encoder.decode(key)); } public boolean verify(byte[] message, byte[] signature) { checkLength(signature, CRYPTO_SIGN_ED25519_BYTES);
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/keys/VerifyKey.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKey { private byte[] key; public VerifyKey(byte[] key) { checkLength(key, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); this.key = key; } public VerifyKey(String key, Encoder encoder) { this(encoder.decode(key)); } public boolean verify(byte[] message, byte[] signature) { checkLength(signature, CRYPTO_SIGN_ED25519_BYTES);
return isValid(sodium().crypto_sign_ed25519_verify_detached(signature, message, message.length, key), "signature was forged or corrupted");
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/Password.java
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // }
import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OUTBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_PWHASH_SCRYPTSALSA208SHA256_STRBYTES; import static org.abstractj.kalium.NaCl.sodium; import org.abstractj.kalium.encoders.Encoder;
package org.abstractj.kalium.crypto; public class Password { public Password() { } public byte[] deriveKey(int length, byte[] passwd, byte[] salt, int opslimit, long memlimit) { byte[] buffer = new byte[length];
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // Path: src/main/java/org/abstractj/kalium/crypto/Password.java import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OUTBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_PWHASH_SCRYPTSALSA208SHA256_STRBYTES; import static org.abstractj.kalium.NaCl.sodium; import org.abstractj.kalium.encoders.Encoder; package org.abstractj.kalium.crypto; public class Password { public Password() { } public byte[] deriveKey(int length, byte[] passwd, byte[] salt, int opslimit, long memlimit) { byte[] buffer = new byte[length];
sodium().crypto_pwhash_scryptsalsa208sha256(buffer, buffer.length, passwd, passwd.length, salt, opslimit, memlimit);
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/Password.java
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // }
import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OUTBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_PWHASH_SCRYPTSALSA208SHA256_STRBYTES; import static org.abstractj.kalium.NaCl.sodium; import org.abstractj.kalium.encoders.Encoder;
package org.abstractj.kalium.crypto; public class Password { public Password() { } public byte[] deriveKey(int length, byte[] passwd, byte[] salt, int opslimit, long memlimit) { byte[] buffer = new byte[length]; sodium().crypto_pwhash_scryptsalsa208sha256(buffer, buffer.length, passwd, passwd.length, salt, opslimit, memlimit); return buffer; }
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // Path: src/main/java/org/abstractj/kalium/crypto/Password.java import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OUTBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_PWHASH_SCRYPTSALSA208SHA256_STRBYTES; import static org.abstractj.kalium.NaCl.sodium; import org.abstractj.kalium.encoders.Encoder; package org.abstractj.kalium.crypto; public class Password { public Password() { } public byte[] deriveKey(int length, byte[] passwd, byte[] salt, int opslimit, long memlimit) { byte[] buffer = new byte[length]; sodium().crypto_pwhash_scryptsalsa208sha256(buffer, buffer.length, passwd, passwd.length, salt, opslimit, memlimit); return buffer; }
public String hash(byte[] passwd, Encoder encoder, byte[] salt, int opslimit, long memlimit) {
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/PublicKey.java
// Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // }
import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class PublicKey implements Key { private final byte[] publicKey; public PublicKey(byte[] publicKey) { this.publicKey = publicKey;
// Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // Path: src/main/java/org/abstractj/kalium/keys/PublicKey.java import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class PublicKey implements Key { private final byte[] publicKey; public PublicKey(byte[] publicKey) { this.publicKey = publicKey;
checkLength(publicKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES);
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class HashTest { private final Hash hash = new Hash(); @Test public void testSha256() throws Exception {
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class HashTest { private final Hash hash = new Hash(); @Test public void testSha256() throws Exception {
final byte[] rawMessage = SHA256_MESSAGE.getBytes();
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class HashTest { private final Hash hash = new Hash(); @Test public void testSha256() throws Exception { final byte[] rawMessage = SHA256_MESSAGE.getBytes(); String result = HEX.encode(hash.sha256(rawMessage));
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class HashTest { private final Hash hash = new Hash(); @Test public void testSha256() throws Exception { final byte[] rawMessage = SHA256_MESSAGE.getBytes(); String result = HEX.encode(hash.sha256(rawMessage));
assertTrue("Hash is invalid", Arrays.equals(SHA256_DIGEST.getBytes(), result.getBytes()));
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class HashTest { private final Hash hash = new Hash(); @Test public void testSha256() throws Exception { final byte[] rawMessage = SHA256_MESSAGE.getBytes(); String result = HEX.encode(hash.sha256(rawMessage)); assertTrue("Hash is invalid", Arrays.equals(SHA256_DIGEST.getBytes(), result.getBytes())); } @Test public void testSha256EmptyString() throws Exception { byte[] result = hash.sha256("".getBytes());
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class HashTest { private final Hash hash = new Hash(); @Test public void testSha256() throws Exception { final byte[] rawMessage = SHA256_MESSAGE.getBytes(); String result = HEX.encode(hash.sha256(rawMessage)); assertTrue("Hash is invalid", Arrays.equals(SHA256_DIGEST.getBytes(), result.getBytes())); } @Test public void testSha256EmptyString() throws Exception { byte[] result = hash.sha256("".getBytes());
assertEquals("Hash is invalid", SHA256_DIGEST_EMPTY_STRING, HEX.encode(result));
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
@Test public void testSha256EmptyString() throws Exception { byte[] result = hash.sha256("".getBytes()); assertEquals("Hash is invalid", SHA256_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testSha256HexString() throws Exception { String result = hash.sha256(SHA256_MESSAGE, HEX); assertEquals("Hash is invalid", SHA256_DIGEST, result); } @Test public void testSha256EmptyHexString() throws Exception { String result = hash.sha256("", HEX); assertEquals("Hash is invalid", SHA256_DIGEST_EMPTY_STRING, result); } @Test public void testSha256NullByte() { try { hash.sha256("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testSha512() throws Exception {
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @Test public void testSha256EmptyString() throws Exception { byte[] result = hash.sha256("".getBytes()); assertEquals("Hash is invalid", SHA256_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testSha256HexString() throws Exception { String result = hash.sha256(SHA256_MESSAGE, HEX); assertEquals("Hash is invalid", SHA256_DIGEST, result); } @Test public void testSha256EmptyHexString() throws Exception { String result = hash.sha256("", HEX); assertEquals("Hash is invalid", SHA256_DIGEST_EMPTY_STRING, result); } @Test public void testSha256NullByte() { try { hash.sha256("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testSha512() throws Exception {
final byte[] rawMessage = SHA512_MESSAGE.getBytes();
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
public void testSha256EmptyString() throws Exception { byte[] result = hash.sha256("".getBytes()); assertEquals("Hash is invalid", SHA256_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testSha256HexString() throws Exception { String result = hash.sha256(SHA256_MESSAGE, HEX); assertEquals("Hash is invalid", SHA256_DIGEST, result); } @Test public void testSha256EmptyHexString() throws Exception { String result = hash.sha256("", HEX); assertEquals("Hash is invalid", SHA256_DIGEST_EMPTY_STRING, result); } @Test public void testSha256NullByte() { try { hash.sha256("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testSha512() throws Exception { final byte[] rawMessage = SHA512_MESSAGE.getBytes(); String result = HEX.encode(hash.sha512(rawMessage));
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; public void testSha256EmptyString() throws Exception { byte[] result = hash.sha256("".getBytes()); assertEquals("Hash is invalid", SHA256_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testSha256HexString() throws Exception { String result = hash.sha256(SHA256_MESSAGE, HEX); assertEquals("Hash is invalid", SHA256_DIGEST, result); } @Test public void testSha256EmptyHexString() throws Exception { String result = hash.sha256("", HEX); assertEquals("Hash is invalid", SHA256_DIGEST_EMPTY_STRING, result); } @Test public void testSha256NullByte() { try { hash.sha256("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testSha512() throws Exception { final byte[] rawMessage = SHA512_MESSAGE.getBytes(); String result = HEX.encode(hash.sha512(rawMessage));
assertTrue("Hash is invalid", Arrays.equals(SHA512_DIGEST.getBytes(), result.getBytes()));
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
public void testSha256HexString() throws Exception { String result = hash.sha256(SHA256_MESSAGE, HEX); assertEquals("Hash is invalid", SHA256_DIGEST, result); } @Test public void testSha256EmptyHexString() throws Exception { String result = hash.sha256("", HEX); assertEquals("Hash is invalid", SHA256_DIGEST_EMPTY_STRING, result); } @Test public void testSha256NullByte() { try { hash.sha256("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testSha512() throws Exception { final byte[] rawMessage = SHA512_MESSAGE.getBytes(); String result = HEX.encode(hash.sha512(rawMessage)); assertTrue("Hash is invalid", Arrays.equals(SHA512_DIGEST.getBytes(), result.getBytes())); } @Test public void testSha512EmptyString() throws Exception { byte[] result = hash.sha512("".getBytes());
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; public void testSha256HexString() throws Exception { String result = hash.sha256(SHA256_MESSAGE, HEX); assertEquals("Hash is invalid", SHA256_DIGEST, result); } @Test public void testSha256EmptyHexString() throws Exception { String result = hash.sha256("", HEX); assertEquals("Hash is invalid", SHA256_DIGEST_EMPTY_STRING, result); } @Test public void testSha256NullByte() { try { hash.sha256("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testSha512() throws Exception { final byte[] rawMessage = SHA512_MESSAGE.getBytes(); String result = HEX.encode(hash.sha512(rawMessage)); assertTrue("Hash is invalid", Arrays.equals(SHA512_DIGEST.getBytes(), result.getBytes())); } @Test public void testSha512EmptyString() throws Exception { byte[] result = hash.sha512("".getBytes());
assertEquals("Hash is invalid", SHA512_DIGEST_EMPTY_STRING, HEX.encode(result));
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
@Test public void testSha512EmptyString() throws Exception { byte[] result = hash.sha512("".getBytes()); assertEquals("Hash is invalid", SHA512_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testSha512HexString() throws Exception { String result = hash.sha512(SHA512_MESSAGE, HEX); assertEquals("Hash is invalid", SHA512_DIGEST, result); } @Test public void testSha512EmptyHexString() throws Exception { String result = hash.sha512("", HEX); assertEquals("Hash is invalid", SHA512_DIGEST_EMPTY_STRING, result); } @Test public void testSha512NullByte() { try { hash.sha512("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2() throws Exception {
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @Test public void testSha512EmptyString() throws Exception { byte[] result = hash.sha512("".getBytes()); assertEquals("Hash is invalid", SHA512_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testSha512HexString() throws Exception { String result = hash.sha512(SHA512_MESSAGE, HEX); assertEquals("Hash is invalid", SHA512_DIGEST, result); } @Test public void testSha512EmptyHexString() throws Exception { String result = hash.sha512("", HEX); assertEquals("Hash is invalid", SHA512_DIGEST_EMPTY_STRING, result); } @Test public void testSha512NullByte() { try { hash.sha512("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2() throws Exception {
final byte[] rawMessage = Blake2_MESSAGE.getBytes();
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
public void testSha512EmptyString() throws Exception { byte[] result = hash.sha512("".getBytes()); assertEquals("Hash is invalid", SHA512_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testSha512HexString() throws Exception { String result = hash.sha512(SHA512_MESSAGE, HEX); assertEquals("Hash is invalid", SHA512_DIGEST, result); } @Test public void testSha512EmptyHexString() throws Exception { String result = hash.sha512("", HEX); assertEquals("Hash is invalid", SHA512_DIGEST_EMPTY_STRING, result); } @Test public void testSha512NullByte() { try { hash.sha512("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2() throws Exception { final byte[] rawMessage = Blake2_MESSAGE.getBytes(); String result = HEX.encode(hash.blake2(rawMessage));
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; public void testSha512EmptyString() throws Exception { byte[] result = hash.sha512("".getBytes()); assertEquals("Hash is invalid", SHA512_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testSha512HexString() throws Exception { String result = hash.sha512(SHA512_MESSAGE, HEX); assertEquals("Hash is invalid", SHA512_DIGEST, result); } @Test public void testSha512EmptyHexString() throws Exception { String result = hash.sha512("", HEX); assertEquals("Hash is invalid", SHA512_DIGEST_EMPTY_STRING, result); } @Test public void testSha512NullByte() { try { hash.sha512("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2() throws Exception { final byte[] rawMessage = Blake2_MESSAGE.getBytes(); String result = HEX.encode(hash.blake2(rawMessage));
assertTrue("Hash is invalid", Arrays.equals(Blake2_DIGEST.getBytes(), result.getBytes()));
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
public void testSha512HexString() throws Exception { String result = hash.sha512(SHA512_MESSAGE, HEX); assertEquals("Hash is invalid", SHA512_DIGEST, result); } @Test public void testSha512EmptyHexString() throws Exception { String result = hash.sha512("", HEX); assertEquals("Hash is invalid", SHA512_DIGEST_EMPTY_STRING, result); } @Test public void testSha512NullByte() { try { hash.sha512("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2() throws Exception { final byte[] rawMessage = Blake2_MESSAGE.getBytes(); String result = HEX.encode(hash.blake2(rawMessage)); assertTrue("Hash is invalid", Arrays.equals(Blake2_DIGEST.getBytes(), result.getBytes())); } @Test public void testBlake2EmptyString() throws Exception { byte[] result = hash.blake2("".getBytes());
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; public void testSha512HexString() throws Exception { String result = hash.sha512(SHA512_MESSAGE, HEX); assertEquals("Hash is invalid", SHA512_DIGEST, result); } @Test public void testSha512EmptyHexString() throws Exception { String result = hash.sha512("", HEX); assertEquals("Hash is invalid", SHA512_DIGEST_EMPTY_STRING, result); } @Test public void testSha512NullByte() { try { hash.sha512("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2() throws Exception { final byte[] rawMessage = Blake2_MESSAGE.getBytes(); String result = HEX.encode(hash.blake2(rawMessage)); assertTrue("Hash is invalid", Arrays.equals(Blake2_DIGEST.getBytes(), result.getBytes())); } @Test public void testBlake2EmptyString() throws Exception { byte[] result = hash.blake2("".getBytes());
assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, HEX.encode(result));
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
@Test public void testBlake2EmptyString() throws Exception { byte[] result = hash.blake2("".getBytes()); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testBlake2HexString() throws Exception { String result = hash.blake2(Blake2_MESSAGE, HEX); assertEquals("Hash is invalid", Blake2_DIGEST, result); } @Test public void testBlake2EmptyHexString() throws Exception { String result = hash.blake2("", HEX); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, result); } @Test public void testBlake2NullByte() { try { hash.blake2("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2WithSaltAndPersonal() {
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @Test public void testBlake2EmptyString() throws Exception { byte[] result = hash.blake2("".getBytes()); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testBlake2HexString() throws Exception { String result = hash.blake2(Blake2_MESSAGE, HEX); assertEquals("Hash is invalid", Blake2_DIGEST, result); } @Test public void testBlake2EmptyHexString() throws Exception { String result = hash.blake2("", HEX); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, result); } @Test public void testBlake2NullByte() { try { hash.blake2("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2WithSaltAndPersonal() {
byte[] result = hash.blake2(Blake2_MESSAGE.getBytes(), Blake2_KEY.getBytes(),
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
@Test public void testBlake2EmptyString() throws Exception { byte[] result = hash.blake2("".getBytes()); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testBlake2HexString() throws Exception { String result = hash.blake2(Blake2_MESSAGE, HEX); assertEquals("Hash is invalid", Blake2_DIGEST, result); } @Test public void testBlake2EmptyHexString() throws Exception { String result = hash.blake2("", HEX); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, result); } @Test public void testBlake2NullByte() { try { hash.blake2("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2WithSaltAndPersonal() { byte[] result = hash.blake2(Blake2_MESSAGE.getBytes(), Blake2_KEY.getBytes(),
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @Test public void testBlake2EmptyString() throws Exception { byte[] result = hash.blake2("".getBytes()); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testBlake2HexString() throws Exception { String result = hash.blake2(Blake2_MESSAGE, HEX); assertEquals("Hash is invalid", Blake2_DIGEST, result); } @Test public void testBlake2EmptyHexString() throws Exception { String result = hash.blake2("", HEX); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, result); } @Test public void testBlake2NullByte() { try { hash.blake2("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2WithSaltAndPersonal() { byte[] result = hash.blake2(Blake2_MESSAGE.getBytes(), Blake2_KEY.getBytes(),
Blake2_SALT.getBytes(),
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
public void testBlake2EmptyString() throws Exception { byte[] result = hash.blake2("".getBytes()); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testBlake2HexString() throws Exception { String result = hash.blake2(Blake2_MESSAGE, HEX); assertEquals("Hash is invalid", Blake2_DIGEST, result); } @Test public void testBlake2EmptyHexString() throws Exception { String result = hash.blake2("", HEX); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, result); } @Test public void testBlake2NullByte() { try { hash.blake2("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2WithSaltAndPersonal() { byte[] result = hash.blake2(Blake2_MESSAGE.getBytes(), Blake2_KEY.getBytes(), Blake2_SALT.getBytes(),
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; public void testBlake2EmptyString() throws Exception { byte[] result = hash.blake2("".getBytes()); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testBlake2HexString() throws Exception { String result = hash.blake2(Blake2_MESSAGE, HEX); assertEquals("Hash is invalid", Blake2_DIGEST, result); } @Test public void testBlake2EmptyHexString() throws Exception { String result = hash.blake2("", HEX); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, result); } @Test public void testBlake2NullByte() { try { hash.blake2("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2WithSaltAndPersonal() { byte[] result = hash.blake2(Blake2_MESSAGE.getBytes(), Blake2_KEY.getBytes(), Blake2_SALT.getBytes(),
Blake2_PERSONAL.getBytes());
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/HashTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail;
byte[] result = hash.blake2("".getBytes()); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testBlake2HexString() throws Exception { String result = hash.blake2(Blake2_MESSAGE, HEX); assertEquals("Hash is invalid", Blake2_DIGEST, result); } @Test public void testBlake2EmptyHexString() throws Exception { String result = hash.blake2("", HEX); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, result); } @Test public void testBlake2NullByte() { try { hash.blake2("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2WithSaltAndPersonal() { byte[] result = hash.blake2(Blake2_MESSAGE.getBytes(), Blake2_KEY.getBytes(), Blake2_SALT.getBytes(), Blake2_PERSONAL.getBytes());
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST = "d281d10296b7bde20df3f3f4a6d1bdb513f4aa4ccb0048c7b2f7f5786b4bcb77"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_DIGEST_EMPTY_STRING = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA256_MESSAGE = "My Bonnie lies over the ocean, my Bonnie lies over the sea"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST = "2823e0373001b5f3aa6db57d07bc588324917fc221dd27975613942d7f2e19bf4" + // "44654c8b9f4f9cb908ef15f2304522e60e9ced3fdec66e34bc2afb52be6ad1c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_DIGEST_EMPTY_STRING = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921" + // "d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SHA512_MESSAGE = "My Bonnie lies over the ocean, Oh bring back my Bonnie to me"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_MESSAGE = "The quick brown fox jumps over the lazy dog"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST = "01718cec35cd3d796dd00020e0bfecb473ad23457d063b75eff29c0ffa2e58a9"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_EMPTY_STRING = "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_DIGEST_WITH_SALT_PERSONAL = "108e81d0c7b0487de45c54554ea35b427f886b098d792497c6a803bbac7a5f7c"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_KEY = "This is a super secret key. Ssshh!"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_SALT = "0123456789abcdef"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String Blake2_PERSONAL = "fedcba9876543210"; // Path: src/test/java/org/abstractj/kalium/crypto/HashTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA256_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA256_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.SHA512_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.SHA512_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_EMPTY_STRING; import static org.abstractj.kalium.fixture.TestVectors.Blake2_DIGEST_WITH_SALT_PERSONAL; import static org.abstractj.kalium.fixture.TestVectors.Blake2_KEY; import static org.abstractj.kalium.fixture.TestVectors.Blake2_SALT; import static org.abstractj.kalium.fixture.TestVectors.Blake2_PERSONAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; byte[] result = hash.blake2("".getBytes()); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, HEX.encode(result)); } @Test public void testBlake2HexString() throws Exception { String result = hash.blake2(Blake2_MESSAGE, HEX); assertEquals("Hash is invalid", Blake2_DIGEST, result); } @Test public void testBlake2EmptyHexString() throws Exception { String result = hash.blake2("", HEX); assertEquals("Hash is invalid", Blake2_DIGEST_EMPTY_STRING, result); } @Test public void testBlake2NullByte() { try { hash.blake2("\0".getBytes()); } catch (Exception e) { fail("Should not raise any exception on null byte"); } } @Test public void testBlake2WithSaltAndPersonal() { byte[] result = hash.blake2(Blake2_MESSAGE.getBytes(), Blake2_KEY.getBytes(), Blake2_SALT.getBytes(), Blake2_PERSONAL.getBytes());
assertEquals("Hash is invalid", Blake2_DIGEST_WITH_SALT_PERSONAL, HEX.encode(result));
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/PrivateKey.java
// Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // }
import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class PrivateKey implements Key { private final byte[] secretKey; public PrivateKey(byte[] secretKey) { this.secretKey = secretKey;
// Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // Path: src/main/java/org/abstractj/kalium/keys/PrivateKey.java import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class PrivateKey implements Key { private final byte[] secretKey; public PrivateKey(byte[] secretKey) { this.secretKey = secretKey;
checkLength(secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES);
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/Random.java
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // }
import static org.abstractj.kalium.NaCl.sodium;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Random { private static final int DEFAULT_SIZE = 32; /** * Generate random bytes * * @param n number or random bytes * @return */ public byte[] randomBytes(int n) { byte[] buffer = new byte[n];
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // Path: src/main/java/org/abstractj/kalium/crypto/Random.java import static org.abstractj.kalium.NaCl.sodium; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class Random { private static final int DEFAULT_SIZE = 32; /** * Generate random bytes * * @param n number or random bytes * @return */ public byte[] randomBytes(int n) { byte[] buffer = new byte[n];
sodium().randombytes(buffer, n);
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/SealedBox.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_SEALBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.isValid;
package org.abstractj.kalium.crypto; public class SealedBox { private byte[] publicKey; private byte[] privateKey; public SealedBox(byte[] publicKey) { this.publicKey = publicKey; this.privateKey = null; }
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/crypto/SealedBox.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_SEALBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.isValid; package org.abstractj.kalium.crypto; public class SealedBox { private byte[] publicKey; private byte[] privateKey; public SealedBox(byte[] publicKey) { this.publicKey = publicKey; this.privateKey = null; }
public SealedBox(String publicKey, Encoder encoder) {
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/SealedBox.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_SEALBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.isValid;
package org.abstractj.kalium.crypto; public class SealedBox { private byte[] publicKey; private byte[] privateKey; public SealedBox(byte[] publicKey) { this.publicKey = publicKey; this.privateKey = null; } public SealedBox(String publicKey, Encoder encoder) { this(encoder.decode(publicKey)); } public SealedBox(byte[] publicKey, byte[] privateKey) { this.publicKey = publicKey; this.privateKey = privateKey; } public SealedBox(String publicKey, String privateKey, Encoder encoder) { this(encoder.decode(publicKey), encoder.decode(privateKey)); } public byte[] encrypt(byte[] message) { if (publicKey == null) throw new RuntimeException("Encryption failed. Public key not available."); byte[] ct = new byte[message.length + CRYPTO_BOX_SEALBYTES];
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/crypto/SealedBox.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_SEALBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.isValid; package org.abstractj.kalium.crypto; public class SealedBox { private byte[] publicKey; private byte[] privateKey; public SealedBox(byte[] publicKey) { this.publicKey = publicKey; this.privateKey = null; } public SealedBox(String publicKey, Encoder encoder) { this(encoder.decode(publicKey)); } public SealedBox(byte[] publicKey, byte[] privateKey) { this.publicKey = publicKey; this.privateKey = privateKey; } public SealedBox(String publicKey, String privateKey, Encoder encoder) { this(encoder.decode(publicKey), encoder.decode(privateKey)); } public byte[] encrypt(byte[] message) { if (publicKey == null) throw new RuntimeException("Encryption failed. Public key not available."); byte[] ct = new byte[message.length + CRYPTO_BOX_SEALBYTES];
isValid(sodium().crypto_box_seal(
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/SealedBox.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_SEALBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.isValid;
package org.abstractj.kalium.crypto; public class SealedBox { private byte[] publicKey; private byte[] privateKey; public SealedBox(byte[] publicKey) { this.publicKey = publicKey; this.privateKey = null; } public SealedBox(String publicKey, Encoder encoder) { this(encoder.decode(publicKey)); } public SealedBox(byte[] publicKey, byte[] privateKey) { this.publicKey = publicKey; this.privateKey = privateKey; } public SealedBox(String publicKey, String privateKey, Encoder encoder) { this(encoder.decode(publicKey), encoder.decode(privateKey)); } public byte[] encrypt(byte[] message) { if (publicKey == null) throw new RuntimeException("Encryption failed. Public key not available."); byte[] ct = new byte[message.length + CRYPTO_BOX_SEALBYTES];
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/crypto/SealedBox.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_SEALBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.isValid; package org.abstractj.kalium.crypto; public class SealedBox { private byte[] publicKey; private byte[] privateKey; public SealedBox(byte[] publicKey) { this.publicKey = publicKey; this.privateKey = null; } public SealedBox(String publicKey, Encoder encoder) { this(encoder.decode(publicKey)); } public SealedBox(byte[] publicKey, byte[] privateKey) { this.publicKey = publicKey; this.privateKey = privateKey; } public SealedBox(String publicKey, String privateKey, Encoder encoder) { this(encoder.decode(publicKey), encoder.decode(privateKey)); } public byte[] encrypt(byte[] message) { if (publicKey == null) throw new RuntimeException("Encryption failed. Public key not available."); byte[] ct = new byte[message.length + CRYPTO_BOX_SEALBYTES];
isValid(sodium().crypto_box_seal(
abstractj/kalium
src/test/java/org/abstractj/kalium/keys/AuthenticationKeyTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_HMAC_SHA512256 = "b2a31b8d4e01afcab2ee545b5caf4e3d212a99d7b3a116a97cec8e83c32e107d"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_KEY = "eea6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff880"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_MESSAGE = "8e993b9f48681273c29650ba32fc76ce48332ea7164d96a4476fb8c531a1186a" + // "c0dfc17c98dce87b4da7f011ec48c97271d2c20f9b928fe2270d6fb863d51738" + // "b48eeee314a7cc8ab932164548e526ae90224368517acfeabd6bb3732bc0e9da" + // "99832b61ca01b6de56244a9e88d5f9b37973f622a43d14a6599b1f654cb45a74" + // "e355a5";
import org.junit.Test; import java.util.Arrays; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.AUTH_HMAC_SHA512256; import static org.abstractj.kalium.fixture.TestVectors.AUTH_KEY; import static org.abstractj.kalium.fixture.TestVectors.AUTH_MESSAGE; import static org.junit.Assert.fail;
/** * Copyright 2015 Cisco Systems, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class AuthenticationKeyTest { @Test public void testAcceptsValidKey() { try {
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_HMAC_SHA512256 = "b2a31b8d4e01afcab2ee545b5caf4e3d212a99d7b3a116a97cec8e83c32e107d"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_KEY = "eea6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff880"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_MESSAGE = "8e993b9f48681273c29650ba32fc76ce48332ea7164d96a4476fb8c531a1186a" + // "c0dfc17c98dce87b4da7f011ec48c97271d2c20f9b928fe2270d6fb863d51738" + // "b48eeee314a7cc8ab932164548e526ae90224368517acfeabd6bb3732bc0e9da" + // "99832b61ca01b6de56244a9e88d5f9b37973f622a43d14a6599b1f654cb45a74" + // "e355a5"; // Path: src/test/java/org/abstractj/kalium/keys/AuthenticationKeyTest.java import org.junit.Test; import java.util.Arrays; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.AUTH_HMAC_SHA512256; import static org.abstractj.kalium.fixture.TestVectors.AUTH_KEY; import static org.abstractj.kalium.fixture.TestVectors.AUTH_MESSAGE; import static org.junit.Assert.fail; /** * Copyright 2015 Cisco Systems, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class AuthenticationKeyTest { @Test public void testAcceptsValidKey() { try {
byte[] rawKey = HEX.decode(AUTH_KEY);
abstractj/kalium
src/test/java/org/abstractj/kalium/keys/AuthenticationKeyTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_HMAC_SHA512256 = "b2a31b8d4e01afcab2ee545b5caf4e3d212a99d7b3a116a97cec8e83c32e107d"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_KEY = "eea6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff880"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_MESSAGE = "8e993b9f48681273c29650ba32fc76ce48332ea7164d96a4476fb8c531a1186a" + // "c0dfc17c98dce87b4da7f011ec48c97271d2c20f9b928fe2270d6fb863d51738" + // "b48eeee314a7cc8ab932164548e526ae90224368517acfeabd6bb3732bc0e9da" + // "99832b61ca01b6de56244a9e88d5f9b37973f622a43d14a6599b1f654cb45a74" + // "e355a5";
import org.junit.Test; import java.util.Arrays; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.AUTH_HMAC_SHA512256; import static org.abstractj.kalium.fixture.TestVectors.AUTH_KEY; import static org.abstractj.kalium.fixture.TestVectors.AUTH_MESSAGE; import static org.junit.Assert.fail;
public void testRejectLongKey() throws Exception { byte[] key = new byte[CRYPTO_AUTH_HMACSHA512256_KEYBYTES + 1]; new AuthenticationKey(key); fail("Should reject long keys"); } @Test public void testSerializesToHex() throws Exception { try { AuthenticationKey key = new AuthenticationKey(AUTH_KEY, HEX); assertEquals("Correct auth key expected", AUTH_KEY, key.toString()); } catch (Exception e) { fail("Should return a valid key size"); } } @Test public void testSerializesToBytes() throws Exception { try { AuthenticationKey key = new AuthenticationKey(AUTH_KEY, HEX); assertTrue("Correct auth key expected", Arrays.equals(HEX.decode(AUTH_KEY), key.toBytes())); } catch (Exception e) { fail("Should return a valid key size"); } } @Test public void testSignMessageAsBytes() throws Exception { byte[] rawKey = HEX.decode(AUTH_KEY); AuthenticationKey key = new AuthenticationKey(rawKey);
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_HMAC_SHA512256 = "b2a31b8d4e01afcab2ee545b5caf4e3d212a99d7b3a116a97cec8e83c32e107d"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_KEY = "eea6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff880"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_MESSAGE = "8e993b9f48681273c29650ba32fc76ce48332ea7164d96a4476fb8c531a1186a" + // "c0dfc17c98dce87b4da7f011ec48c97271d2c20f9b928fe2270d6fb863d51738" + // "b48eeee314a7cc8ab932164548e526ae90224368517acfeabd6bb3732bc0e9da" + // "99832b61ca01b6de56244a9e88d5f9b37973f622a43d14a6599b1f654cb45a74" + // "e355a5"; // Path: src/test/java/org/abstractj/kalium/keys/AuthenticationKeyTest.java import org.junit.Test; import java.util.Arrays; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.AUTH_HMAC_SHA512256; import static org.abstractj.kalium.fixture.TestVectors.AUTH_KEY; import static org.abstractj.kalium.fixture.TestVectors.AUTH_MESSAGE; import static org.junit.Assert.fail; public void testRejectLongKey() throws Exception { byte[] key = new byte[CRYPTO_AUTH_HMACSHA512256_KEYBYTES + 1]; new AuthenticationKey(key); fail("Should reject long keys"); } @Test public void testSerializesToHex() throws Exception { try { AuthenticationKey key = new AuthenticationKey(AUTH_KEY, HEX); assertEquals("Correct auth key expected", AUTH_KEY, key.toString()); } catch (Exception e) { fail("Should return a valid key size"); } } @Test public void testSerializesToBytes() throws Exception { try { AuthenticationKey key = new AuthenticationKey(AUTH_KEY, HEX); assertTrue("Correct auth key expected", Arrays.equals(HEX.decode(AUTH_KEY), key.toBytes())); } catch (Exception e) { fail("Should return a valid key size"); } } @Test public void testSignMessageAsBytes() throws Exception { byte[] rawKey = HEX.decode(AUTH_KEY); AuthenticationKey key = new AuthenticationKey(rawKey);
byte[] mac = key.sign(HEX.decode(AUTH_MESSAGE));
abstractj/kalium
src/test/java/org/abstractj/kalium/keys/AuthenticationKeyTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_HMAC_SHA512256 = "b2a31b8d4e01afcab2ee545b5caf4e3d212a99d7b3a116a97cec8e83c32e107d"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_KEY = "eea6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff880"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_MESSAGE = "8e993b9f48681273c29650ba32fc76ce48332ea7164d96a4476fb8c531a1186a" + // "c0dfc17c98dce87b4da7f011ec48c97271d2c20f9b928fe2270d6fb863d51738" + // "b48eeee314a7cc8ab932164548e526ae90224368517acfeabd6bb3732bc0e9da" + // "99832b61ca01b6de56244a9e88d5f9b37973f622a43d14a6599b1f654cb45a74" + // "e355a5";
import org.junit.Test; import java.util.Arrays; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.AUTH_HMAC_SHA512256; import static org.abstractj.kalium.fixture.TestVectors.AUTH_KEY; import static org.abstractj.kalium.fixture.TestVectors.AUTH_MESSAGE; import static org.junit.Assert.fail;
byte[] key = new byte[CRYPTO_AUTH_HMACSHA512256_KEYBYTES + 1]; new AuthenticationKey(key); fail("Should reject long keys"); } @Test public void testSerializesToHex() throws Exception { try { AuthenticationKey key = new AuthenticationKey(AUTH_KEY, HEX); assertEquals("Correct auth key expected", AUTH_KEY, key.toString()); } catch (Exception e) { fail("Should return a valid key size"); } } @Test public void testSerializesToBytes() throws Exception { try { AuthenticationKey key = new AuthenticationKey(AUTH_KEY, HEX); assertTrue("Correct auth key expected", Arrays.equals(HEX.decode(AUTH_KEY), key.toBytes())); } catch (Exception e) { fail("Should return a valid key size"); } } @Test public void testSignMessageAsBytes() throws Exception { byte[] rawKey = HEX.decode(AUTH_KEY); AuthenticationKey key = new AuthenticationKey(rawKey); byte[] mac = key.sign(HEX.decode(AUTH_MESSAGE));
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_HMAC_SHA512256 = "b2a31b8d4e01afcab2ee545b5caf4e3d212a99d7b3a116a97cec8e83c32e107d"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_KEY = "eea6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff880"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String AUTH_MESSAGE = "8e993b9f48681273c29650ba32fc76ce48332ea7164d96a4476fb8c531a1186a" + // "c0dfc17c98dce87b4da7f011ec48c97271d2c20f9b928fe2270d6fb863d51738" + // "b48eeee314a7cc8ab932164548e526ae90224368517acfeabd6bb3732bc0e9da" + // "99832b61ca01b6de56244a9e88d5f9b37973f622a43d14a6599b1f654cb45a74" + // "e355a5"; // Path: src/test/java/org/abstractj/kalium/keys/AuthenticationKeyTest.java import org.junit.Test; import java.util.Arrays; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.AUTH_HMAC_SHA512256; import static org.abstractj.kalium.fixture.TestVectors.AUTH_KEY; import static org.abstractj.kalium.fixture.TestVectors.AUTH_MESSAGE; import static org.junit.Assert.fail; byte[] key = new byte[CRYPTO_AUTH_HMACSHA512256_KEYBYTES + 1]; new AuthenticationKey(key); fail("Should reject long keys"); } @Test public void testSerializesToHex() throws Exception { try { AuthenticationKey key = new AuthenticationKey(AUTH_KEY, HEX); assertEquals("Correct auth key expected", AUTH_KEY, key.toString()); } catch (Exception e) { fail("Should return a valid key size"); } } @Test public void testSerializesToBytes() throws Exception { try { AuthenticationKey key = new AuthenticationKey(AUTH_KEY, HEX); assertTrue("Correct auth key expected", Arrays.equals(HEX.decode(AUTH_KEY), key.toBytes())); } catch (Exception e) { fail("Should return a valid key size"); } } @Test public void testSignMessageAsBytes() throws Exception { byte[] rawKey = HEX.decode(AUTH_KEY); AuthenticationKey key = new AuthenticationKey(rawKey); byte[] mac = key.sign(HEX.decode(AUTH_MESSAGE));
assertTrue("Message sign has failed", Arrays.equals(HEX.decode(AUTH_HMAC_SHA512256), mac));
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/ShortHash.java
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SHORTHASH_SIPHASH24_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SHORTHASH_SIPHASH24_KEYBYTES; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid;
/** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHash { public byte[] siphash24(byte[] message, byte[] key) { byte[] buffer = new byte[CRYPTO_SHORTHASH_SIPHASH24_BYTES];
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/crypto/ShortHash.java import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SHORTHASH_SIPHASH24_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SHORTHASH_SIPHASH24_KEYBYTES; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; /** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHash { public byte[] siphash24(byte[] message, byte[] key) { byte[] buffer = new byte[CRYPTO_SHORTHASH_SIPHASH24_BYTES];
checkLength(key, CRYPTO_SHORTHASH_SIPHASH24_KEYBYTES);
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/ShortHash.java
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SHORTHASH_SIPHASH24_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SHORTHASH_SIPHASH24_KEYBYTES; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid;
/** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHash { public byte[] siphash24(byte[] message, byte[] key) { byte[] buffer = new byte[CRYPTO_SHORTHASH_SIPHASH24_BYTES]; checkLength(key, CRYPTO_SHORTHASH_SIPHASH24_KEYBYTES);
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/crypto/ShortHash.java import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SHORTHASH_SIPHASH24_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SHORTHASH_SIPHASH24_KEYBYTES; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; /** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHash { public byte[] siphash24(byte[] message, byte[] key) { byte[] buffer = new byte[CRYPTO_SHORTHASH_SIPHASH24_BYTES]; checkLength(key, CRYPTO_SHORTHASH_SIPHASH24_KEYBYTES);
isValid(sodium().crypto_shorthash_siphash24(buffer, message, message.length, key), "Hashing failed");
abstractj/kalium
src/main/java/org/abstractj/kalium/crypto/ShortHash.java
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SHORTHASH_SIPHASH24_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SHORTHASH_SIPHASH24_KEYBYTES; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid;
/** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHash { public byte[] siphash24(byte[] message, byte[] key) { byte[] buffer = new byte[CRYPTO_SHORTHASH_SIPHASH24_BYTES]; checkLength(key, CRYPTO_SHORTHASH_SIPHASH24_KEYBYTES);
// Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/crypto/ShortHash.java import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SHORTHASH_SIPHASH24_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SHORTHASH_SIPHASH24_KEYBYTES; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; /** * Copyright 2017 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class ShortHash { public byte[] siphash24(byte[] message, byte[] key) { byte[] buffer = new byte[CRYPTO_SHORTHASH_SIPHASH24_BYTES]; checkLength(key, CRYPTO_SHORTHASH_SIPHASH24_KEYBYTES);
isValid(sodium().crypto_shorthash_siphash24(buffer, message, message.length, key), "Hashing failed");
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/AuthenticationKey.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2015 Cisco Systems, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class AuthenticationKey implements Key { private byte[] key; public AuthenticationKey(byte[] key) { this.key = key;
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/keys/AuthenticationKey.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2015 Cisco Systems, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class AuthenticationKey implements Key { private byte[] key; public AuthenticationKey(byte[] key) { this.key = key;
checkLength(key, CRYPTO_AUTH_HMACSHA512256_KEYBYTES);
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/AuthenticationKey.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2015 Cisco Systems, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class AuthenticationKey implements Key { private byte[] key; public AuthenticationKey(byte[] key) { this.key = key; checkLength(key, CRYPTO_AUTH_HMACSHA512256_KEYBYTES); }
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/keys/AuthenticationKey.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2015 Cisco Systems, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class AuthenticationKey implements Key { private byte[] key; public AuthenticationKey(byte[] key) { this.key = key; checkLength(key, CRYPTO_AUTH_HMACSHA512256_KEYBYTES); }
public AuthenticationKey(String key, Encoder encoder) {
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/AuthenticationKey.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2015 Cisco Systems, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class AuthenticationKey implements Key { private byte[] key; public AuthenticationKey(byte[] key) { this.key = key; checkLength(key, CRYPTO_AUTH_HMACSHA512256_KEYBYTES); } public AuthenticationKey(String key, Encoder encoder) { this(encoder.decode(key)); } public byte[] sign(byte[] message) { byte[] mac = new byte[CRYPTO_AUTH_HMACSHA512256_BYTES];
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/keys/AuthenticationKey.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2015 Cisco Systems, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class AuthenticationKey implements Key { private byte[] key; public AuthenticationKey(byte[] key) { this.key = key; checkLength(key, CRYPTO_AUTH_HMACSHA512256_KEYBYTES); } public AuthenticationKey(String key, Encoder encoder) { this(encoder.decode(key)); } public byte[] sign(byte[] message) { byte[] mac = new byte[CRYPTO_AUTH_HMACSHA512256_BYTES];
sodium().crypto_auth_hmacsha512256(mac, message, message.length, key);
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/AuthenticationKey.java
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // }
import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2015 Cisco Systems, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class AuthenticationKey implements Key { private byte[] key; public AuthenticationKey(byte[] key) { this.key = key; checkLength(key, CRYPTO_AUTH_HMACSHA512256_KEYBYTES); } public AuthenticationKey(String key, Encoder encoder) { this(encoder.decode(key)); } public byte[] sign(byte[] message) { byte[] mac = new byte[CRYPTO_AUTH_HMACSHA512256_BYTES]; sodium().crypto_auth_hmacsha512256(mac, message, message.length, key); return mac; } public String sign(String message, Encoder encoder) { byte[] signature = sign(encoder.decode(message)); return encoder.encode(signature); } public boolean verify(byte[] message, byte[] signature) { checkLength(signature, CRYPTO_AUTH_HMACSHA512256_BYTES);
// Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // Path: src/main/java/org/abstractj/kalium/keys/AuthenticationKey.java import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_BYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_AUTH_HMACSHA512256_KEYBYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2015 Cisco Systems, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class AuthenticationKey implements Key { private byte[] key; public AuthenticationKey(byte[] key) { this.key = key; checkLength(key, CRYPTO_AUTH_HMACSHA512256_KEYBYTES); } public AuthenticationKey(String key, Encoder encoder) { this(encoder.decode(key)); } public byte[] sign(byte[] message) { byte[] mac = new byte[CRYPTO_AUTH_HMACSHA512256_BYTES]; sodium().crypto_auth_hmacsha512256(mac, message, message.length, key); return mac; } public String sign(String message, Encoder encoder) { byte[] signature = sign(encoder.decode(message)); return encoder.encode(signature); } public boolean verify(byte[] message, byte[] signature) { checkLength(signature, CRYPTO_AUTH_HMACSHA512256_BYTES);
return isValid(sodium().crypto_auth_hmacsha512256_verify(signature, message, message.length, key), "signature was forged or corrupted");
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/BoxTest.java
// Path: src/main/java/org/abstractj/kalium/keys/PrivateKey.java // public class PrivateKey implements Key { // // private final byte[] secretKey; // // public PrivateKey(byte[] secretKey) { // this.secretKey = secretKey; // checkLength(secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // } // // public PrivateKey(String secretKey) { // this.secretKey = HEX.decode(secretKey); // checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // } // // @Override // public byte[] toBytes() { // return secretKey; // } // // @Override // public String toString() { // return HEX.encode(secretKey); // } // } // // Path: src/main/java/org/abstractj/kalium/keys/PublicKey.java // public class PublicKey implements Key { // // private final byte[] publicKey; // // public PublicKey(byte[] publicKey) { // this.publicKey = publicKey; // checkLength(publicKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); // } // // public PublicKey(String publicKey) { // this.publicKey = HEX.decode(publicKey); // } // // public byte[] toBytes() { // return publicKey; // } // // @Override // public String toString() { // return HEX.encode(publicKey); // } // } // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String ALICE_PRIVATE_KEY = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String ALICE_PUBLIC_KEY = "8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOB_PRIVATE_KEY = "5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOB_PUBLIC_KEY = "de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOX_CIPHERTEXT = "f3ffc7703f9400e52a7dfb4b3d3305d98e993b9f48681273c29650ba32fc76ce" + // "48332ea7164d96a4476fb8c531a1186ac0dfc17c98dce87b4da7f011ec48c972" + // "71d2c20f9b928fe2270d6fb863d51738b48eeee314a7cc8ab932164548e526ae" + // "90224368517acfeabd6bb3732bc0e9da99832b61ca01b6de56244a9e88d5f9b3" + // "7973f622a43d14a6599b1f654cb45a74e355a5"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOX_MESSAGE = "be075fc53c81f2d5cf141316ebeb0c7b5228c52a4c62cbd44b66849b64244ffc" + // "e5ecbaaf33bd751a1ac728d45e6c61296cdc3c01233561f41db66cce314adb31" + // "0e3be8250c46f06dceea3a7fa1348057e2f6556ad6b1318a024a838f21af1fde" + // "048977eb48f59ffd4924ca1c60902e52f0a089bc76897040e082f93776384864" + // "5e0705"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOX_NONCE = "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37";
import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.abstractj.kalium.keys.PrivateKey; import org.abstractj.kalium.keys.PublicKey; import org.junit.Test; import java.util.Arrays; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.ALICE_PRIVATE_KEY; import static org.abstractj.kalium.fixture.TestVectors.ALICE_PUBLIC_KEY; import static org.abstractj.kalium.fixture.TestVectors.BOB_PRIVATE_KEY; import static org.abstractj.kalium.fixture.TestVectors.BOB_PUBLIC_KEY; import static org.abstractj.kalium.fixture.TestVectors.BOX_CIPHERTEXT; import static org.abstractj.kalium.fixture.TestVectors.BOX_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.BOX_NONCE;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class BoxTest { @Test public void testAcceptStrings() throws Exception { try {
// Path: src/main/java/org/abstractj/kalium/keys/PrivateKey.java // public class PrivateKey implements Key { // // private final byte[] secretKey; // // public PrivateKey(byte[] secretKey) { // this.secretKey = secretKey; // checkLength(secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // } // // public PrivateKey(String secretKey) { // this.secretKey = HEX.decode(secretKey); // checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // } // // @Override // public byte[] toBytes() { // return secretKey; // } // // @Override // public String toString() { // return HEX.encode(secretKey); // } // } // // Path: src/main/java/org/abstractj/kalium/keys/PublicKey.java // public class PublicKey implements Key { // // private final byte[] publicKey; // // public PublicKey(byte[] publicKey) { // this.publicKey = publicKey; // checkLength(publicKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); // } // // public PublicKey(String publicKey) { // this.publicKey = HEX.decode(publicKey); // } // // public byte[] toBytes() { // return publicKey; // } // // @Override // public String toString() { // return HEX.encode(publicKey); // } // } // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String ALICE_PRIVATE_KEY = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String ALICE_PUBLIC_KEY = "8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOB_PRIVATE_KEY = "5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOB_PUBLIC_KEY = "de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOX_CIPHERTEXT = "f3ffc7703f9400e52a7dfb4b3d3305d98e993b9f48681273c29650ba32fc76ce" + // "48332ea7164d96a4476fb8c531a1186ac0dfc17c98dce87b4da7f011ec48c972" + // "71d2c20f9b928fe2270d6fb863d51738b48eeee314a7cc8ab932164548e526ae" + // "90224368517acfeabd6bb3732bc0e9da99832b61ca01b6de56244a9e88d5f9b3" + // "7973f622a43d14a6599b1f654cb45a74e355a5"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOX_MESSAGE = "be075fc53c81f2d5cf141316ebeb0c7b5228c52a4c62cbd44b66849b64244ffc" + // "e5ecbaaf33bd751a1ac728d45e6c61296cdc3c01233561f41db66cce314adb31" + // "0e3be8250c46f06dceea3a7fa1348057e2f6556ad6b1318a024a838f21af1fde" + // "048977eb48f59ffd4924ca1c60902e52f0a089bc76897040e082f93776384864" + // "5e0705"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOX_NONCE = "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37"; // Path: src/test/java/org/abstractj/kalium/crypto/BoxTest.java import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.abstractj.kalium.keys.PrivateKey; import org.abstractj.kalium.keys.PublicKey; import org.junit.Test; import java.util.Arrays; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.ALICE_PRIVATE_KEY; import static org.abstractj.kalium.fixture.TestVectors.ALICE_PUBLIC_KEY; import static org.abstractj.kalium.fixture.TestVectors.BOB_PRIVATE_KEY; import static org.abstractj.kalium.fixture.TestVectors.BOB_PUBLIC_KEY; import static org.abstractj.kalium.fixture.TestVectors.BOX_CIPHERTEXT; import static org.abstractj.kalium.fixture.TestVectors.BOX_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.BOX_NONCE; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class BoxTest { @Test public void testAcceptStrings() throws Exception { try {
new Box(ALICE_PUBLIC_KEY, BOB_PRIVATE_KEY, HEX);
abstractj/kalium
src/test/java/org/abstractj/kalium/crypto/BoxTest.java
// Path: src/main/java/org/abstractj/kalium/keys/PrivateKey.java // public class PrivateKey implements Key { // // private final byte[] secretKey; // // public PrivateKey(byte[] secretKey) { // this.secretKey = secretKey; // checkLength(secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // } // // public PrivateKey(String secretKey) { // this.secretKey = HEX.decode(secretKey); // checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // } // // @Override // public byte[] toBytes() { // return secretKey; // } // // @Override // public String toString() { // return HEX.encode(secretKey); // } // } // // Path: src/main/java/org/abstractj/kalium/keys/PublicKey.java // public class PublicKey implements Key { // // private final byte[] publicKey; // // public PublicKey(byte[] publicKey) { // this.publicKey = publicKey; // checkLength(publicKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); // } // // public PublicKey(String publicKey) { // this.publicKey = HEX.decode(publicKey); // } // // public byte[] toBytes() { // return publicKey; // } // // @Override // public String toString() { // return HEX.encode(publicKey); // } // } // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String ALICE_PRIVATE_KEY = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String ALICE_PUBLIC_KEY = "8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOB_PRIVATE_KEY = "5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOB_PUBLIC_KEY = "de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOX_CIPHERTEXT = "f3ffc7703f9400e52a7dfb4b3d3305d98e993b9f48681273c29650ba32fc76ce" + // "48332ea7164d96a4476fb8c531a1186ac0dfc17c98dce87b4da7f011ec48c972" + // "71d2c20f9b928fe2270d6fb863d51738b48eeee314a7cc8ab932164548e526ae" + // "90224368517acfeabd6bb3732bc0e9da99832b61ca01b6de56244a9e88d5f9b3" + // "7973f622a43d14a6599b1f654cb45a74e355a5"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOX_MESSAGE = "be075fc53c81f2d5cf141316ebeb0c7b5228c52a4c62cbd44b66849b64244ffc" + // "e5ecbaaf33bd751a1ac728d45e6c61296cdc3c01233561f41db66cce314adb31" + // "0e3be8250c46f06dceea3a7fa1348057e2f6556ad6b1318a024a838f21af1fde" + // "048977eb48f59ffd4924ca1c60902e52f0a089bc76897040e082f93776384864" + // "5e0705"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOX_NONCE = "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37";
import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.abstractj.kalium.keys.PrivateKey; import org.abstractj.kalium.keys.PublicKey; import org.junit.Test; import java.util.Arrays; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.ALICE_PRIVATE_KEY; import static org.abstractj.kalium.fixture.TestVectors.ALICE_PUBLIC_KEY; import static org.abstractj.kalium.fixture.TestVectors.BOB_PRIVATE_KEY; import static org.abstractj.kalium.fixture.TestVectors.BOB_PUBLIC_KEY; import static org.abstractj.kalium.fixture.TestVectors.BOX_CIPHERTEXT; import static org.abstractj.kalium.fixture.TestVectors.BOX_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.BOX_NONCE;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class BoxTest { @Test public void testAcceptStrings() throws Exception { try {
// Path: src/main/java/org/abstractj/kalium/keys/PrivateKey.java // public class PrivateKey implements Key { // // private final byte[] secretKey; // // public PrivateKey(byte[] secretKey) { // this.secretKey = secretKey; // checkLength(secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // } // // public PrivateKey(String secretKey) { // this.secretKey = HEX.decode(secretKey); // checkLength(this.secretKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); // } // // @Override // public byte[] toBytes() { // return secretKey; // } // // @Override // public String toString() { // return HEX.encode(secretKey); // } // } // // Path: src/main/java/org/abstractj/kalium/keys/PublicKey.java // public class PublicKey implements Key { // // private final byte[] publicKey; // // public PublicKey(byte[] publicKey) { // this.publicKey = publicKey; // checkLength(publicKey, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); // } // // public PublicKey(String publicKey) { // this.publicKey = HEX.decode(publicKey); // } // // public byte[] toBytes() { // return publicKey; // } // // @Override // public String toString() { // return HEX.encode(publicKey); // } // } // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String ALICE_PRIVATE_KEY = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String ALICE_PUBLIC_KEY = "8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOB_PRIVATE_KEY = "5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOB_PUBLIC_KEY = "de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOX_CIPHERTEXT = "f3ffc7703f9400e52a7dfb4b3d3305d98e993b9f48681273c29650ba32fc76ce" + // "48332ea7164d96a4476fb8c531a1186ac0dfc17c98dce87b4da7f011ec48c972" + // "71d2c20f9b928fe2270d6fb863d51738b48eeee314a7cc8ab932164548e526ae" + // "90224368517acfeabd6bb3732bc0e9da99832b61ca01b6de56244a9e88d5f9b3" + // "7973f622a43d14a6599b1f654cb45a74e355a5"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOX_MESSAGE = "be075fc53c81f2d5cf141316ebeb0c7b5228c52a4c62cbd44b66849b64244ffc" + // "e5ecbaaf33bd751a1ac728d45e6c61296cdc3c01233561f41db66cce314adb31" + // "0e3be8250c46f06dceea3a7fa1348057e2f6556ad6b1318a024a838f21af1fde" + // "048977eb48f59ffd4924ca1c60902e52f0a089bc76897040e082f93776384864" + // "5e0705"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String BOX_NONCE = "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37"; // Path: src/test/java/org/abstractj/kalium/crypto/BoxTest.java import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.abstractj.kalium.keys.PrivateKey; import org.abstractj.kalium.keys.PublicKey; import org.junit.Test; import java.util.Arrays; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.ALICE_PRIVATE_KEY; import static org.abstractj.kalium.fixture.TestVectors.ALICE_PUBLIC_KEY; import static org.abstractj.kalium.fixture.TestVectors.BOB_PRIVATE_KEY; import static org.abstractj.kalium.fixture.TestVectors.BOB_PUBLIC_KEY; import static org.abstractj.kalium.fixture.TestVectors.BOX_CIPHERTEXT; import static org.abstractj.kalium.fixture.TestVectors.BOX_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.BOX_NONCE; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.crypto; public class BoxTest { @Test public void testAcceptStrings() throws Exception { try {
new Box(ALICE_PUBLIC_KEY, BOB_PRIVATE_KEY, HEX);
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/SigningKey.java
// Path: src/main/java/org/abstractj/kalium/crypto/Random.java // public class Random { // // private static final int DEFAULT_SIZE = 32; // // /** // * Generate random bytes // * // * @param n number or random bytes // * @return // */ // public byte[] randomBytes(int n) { // byte[] buffer = new byte[n]; // sodium().randombytes(buffer, n); // return buffer; // } // // public byte[] randomBytes() { // byte[] buffer = new byte[DEFAULT_SIZE]; // sodium().randombytes(buffer, DEFAULT_SIZE); // return buffer; // } // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public class Util { // // private static final int DEFAULT_SIZE = 32; // // public static byte[] prependZeros(int n, byte[] message) { // byte[] result = new byte[n + message.length]; // System.arraycopy(message, 0, result, n, message.length); // return result; // } // // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // public static byte[] zeros(int n) { // return new byte[n]; // } // // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // public static byte[] merge(byte[] signature, byte[] message) { // byte[] result = new byte[signature.length + message.length]; // System.arraycopy(signature, 0, result, 0, signature.length); // System.arraycopy(message, 0, result, signature.length, message.length); // return result; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import jnr.ffi.byref.LongLongByReference; import org.abstractj.kalium.crypto.Random; import org.abstractj.kalium.crypto.Util; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.slice; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class SigningKey { private final byte[] seed; private final byte[] secretKey; private final VerifyKey verifyKey; public SigningKey(byte[] seed) {
// Path: src/main/java/org/abstractj/kalium/crypto/Random.java // public class Random { // // private static final int DEFAULT_SIZE = 32; // // /** // * Generate random bytes // * // * @param n number or random bytes // * @return // */ // public byte[] randomBytes(int n) { // byte[] buffer = new byte[n]; // sodium().randombytes(buffer, n); // return buffer; // } // // public byte[] randomBytes() { // byte[] buffer = new byte[DEFAULT_SIZE]; // sodium().randombytes(buffer, DEFAULT_SIZE); // return buffer; // } // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public class Util { // // private static final int DEFAULT_SIZE = 32; // // public static byte[] prependZeros(int n, byte[] message) { // byte[] result = new byte[n + message.length]; // System.arraycopy(message, 0, result, n, message.length); // return result; // } // // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // public static byte[] zeros(int n) { // return new byte[n]; // } // // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // public static byte[] merge(byte[] signature, byte[] message) { // byte[] result = new byte[signature.length + message.length]; // System.arraycopy(signature, 0, result, 0, signature.length); // System.arraycopy(message, 0, result, signature.length, message.length); // return result; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/keys/SigningKey.java import jnr.ffi.byref.LongLongByReference; import org.abstractj.kalium.crypto.Random; import org.abstractj.kalium.crypto.Util; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.slice; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class SigningKey { private final byte[] seed; private final byte[] secretKey; private final VerifyKey verifyKey; public SigningKey(byte[] seed) {
checkLength(seed, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES);
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/SigningKey.java
// Path: src/main/java/org/abstractj/kalium/crypto/Random.java // public class Random { // // private static final int DEFAULT_SIZE = 32; // // /** // * Generate random bytes // * // * @param n number or random bytes // * @return // */ // public byte[] randomBytes(int n) { // byte[] buffer = new byte[n]; // sodium().randombytes(buffer, n); // return buffer; // } // // public byte[] randomBytes() { // byte[] buffer = new byte[DEFAULT_SIZE]; // sodium().randombytes(buffer, DEFAULT_SIZE); // return buffer; // } // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public class Util { // // private static final int DEFAULT_SIZE = 32; // // public static byte[] prependZeros(int n, byte[] message) { // byte[] result = new byte[n + message.length]; // System.arraycopy(message, 0, result, n, message.length); // return result; // } // // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // public static byte[] zeros(int n) { // return new byte[n]; // } // // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // public static byte[] merge(byte[] signature, byte[] message) { // byte[] result = new byte[signature.length + message.length]; // System.arraycopy(signature, 0, result, 0, signature.length); // System.arraycopy(message, 0, result, signature.length, message.length); // return result; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import jnr.ffi.byref.LongLongByReference; import org.abstractj.kalium.crypto.Random; import org.abstractj.kalium.crypto.Util; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.slice; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class SigningKey { private final byte[] seed; private final byte[] secretKey; private final VerifyKey verifyKey; public SigningKey(byte[] seed) { checkLength(seed, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.seed = seed;
// Path: src/main/java/org/abstractj/kalium/crypto/Random.java // public class Random { // // private static final int DEFAULT_SIZE = 32; // // /** // * Generate random bytes // * // * @param n number or random bytes // * @return // */ // public byte[] randomBytes(int n) { // byte[] buffer = new byte[n]; // sodium().randombytes(buffer, n); // return buffer; // } // // public byte[] randomBytes() { // byte[] buffer = new byte[DEFAULT_SIZE]; // sodium().randombytes(buffer, DEFAULT_SIZE); // return buffer; // } // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public class Util { // // private static final int DEFAULT_SIZE = 32; // // public static byte[] prependZeros(int n, byte[] message) { // byte[] result = new byte[n + message.length]; // System.arraycopy(message, 0, result, n, message.length); // return result; // } // // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // public static byte[] zeros(int n) { // return new byte[n]; // } // // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // public static byte[] merge(byte[] signature, byte[] message) { // byte[] result = new byte[signature.length + message.length]; // System.arraycopy(signature, 0, result, 0, signature.length); // System.arraycopy(message, 0, result, signature.length, message.length); // return result; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/keys/SigningKey.java import jnr.ffi.byref.LongLongByReference; import org.abstractj.kalium.crypto.Random; import org.abstractj.kalium.crypto.Util; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.slice; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class SigningKey { private final byte[] seed; private final byte[] secretKey; private final VerifyKey verifyKey; public SigningKey(byte[] seed) { checkLength(seed, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.seed = seed;
this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES * 2);
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/SigningKey.java
// Path: src/main/java/org/abstractj/kalium/crypto/Random.java // public class Random { // // private static final int DEFAULT_SIZE = 32; // // /** // * Generate random bytes // * // * @param n number or random bytes // * @return // */ // public byte[] randomBytes(int n) { // byte[] buffer = new byte[n]; // sodium().randombytes(buffer, n); // return buffer; // } // // public byte[] randomBytes() { // byte[] buffer = new byte[DEFAULT_SIZE]; // sodium().randombytes(buffer, DEFAULT_SIZE); // return buffer; // } // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public class Util { // // private static final int DEFAULT_SIZE = 32; // // public static byte[] prependZeros(int n, byte[] message) { // byte[] result = new byte[n + message.length]; // System.arraycopy(message, 0, result, n, message.length); // return result; // } // // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // public static byte[] zeros(int n) { // return new byte[n]; // } // // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // public static byte[] merge(byte[] signature, byte[] message) { // byte[] result = new byte[signature.length + message.length]; // System.arraycopy(signature, 0, result, 0, signature.length); // System.arraycopy(message, 0, result, signature.length, message.length); // return result; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import jnr.ffi.byref.LongLongByReference; import org.abstractj.kalium.crypto.Random; import org.abstractj.kalium.crypto.Util; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.slice; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class SigningKey { private final byte[] seed; private final byte[] secretKey; private final VerifyKey verifyKey; public SigningKey(byte[] seed) { checkLength(seed, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.seed = seed; this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES * 2); byte[] publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES);
// Path: src/main/java/org/abstractj/kalium/crypto/Random.java // public class Random { // // private static final int DEFAULT_SIZE = 32; // // /** // * Generate random bytes // * // * @param n number or random bytes // * @return // */ // public byte[] randomBytes(int n) { // byte[] buffer = new byte[n]; // sodium().randombytes(buffer, n); // return buffer; // } // // public byte[] randomBytes() { // byte[] buffer = new byte[DEFAULT_SIZE]; // sodium().randombytes(buffer, DEFAULT_SIZE); // return buffer; // } // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public class Util { // // private static final int DEFAULT_SIZE = 32; // // public static byte[] prependZeros(int n, byte[] message) { // byte[] result = new byte[n + message.length]; // System.arraycopy(message, 0, result, n, message.length); // return result; // } // // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // public static byte[] zeros(int n) { // return new byte[n]; // } // // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // public static byte[] merge(byte[] signature, byte[] message) { // byte[] result = new byte[signature.length + message.length]; // System.arraycopy(signature, 0, result, 0, signature.length); // System.arraycopy(message, 0, result, signature.length, message.length); // return result; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/keys/SigningKey.java import jnr.ffi.byref.LongLongByReference; import org.abstractj.kalium.crypto.Random; import org.abstractj.kalium.crypto.Util; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.slice; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class SigningKey { private final byte[] seed; private final byte[] secretKey; private final VerifyKey verifyKey; public SigningKey(byte[] seed) { checkLength(seed, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.seed = seed; this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES * 2); byte[] publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES);
isValid(sodium().crypto_sign_ed25519_seed_keypair(publicKey, secretKey, seed),
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/SigningKey.java
// Path: src/main/java/org/abstractj/kalium/crypto/Random.java // public class Random { // // private static final int DEFAULT_SIZE = 32; // // /** // * Generate random bytes // * // * @param n number or random bytes // * @return // */ // public byte[] randomBytes(int n) { // byte[] buffer = new byte[n]; // sodium().randombytes(buffer, n); // return buffer; // } // // public byte[] randomBytes() { // byte[] buffer = new byte[DEFAULT_SIZE]; // sodium().randombytes(buffer, DEFAULT_SIZE); // return buffer; // } // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public class Util { // // private static final int DEFAULT_SIZE = 32; // // public static byte[] prependZeros(int n, byte[] message) { // byte[] result = new byte[n + message.length]; // System.arraycopy(message, 0, result, n, message.length); // return result; // } // // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // public static byte[] zeros(int n) { // return new byte[n]; // } // // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // public static byte[] merge(byte[] signature, byte[] message) { // byte[] result = new byte[signature.length + message.length]; // System.arraycopy(signature, 0, result, 0, signature.length); // System.arraycopy(message, 0, result, signature.length, message.length); // return result; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import jnr.ffi.byref.LongLongByReference; import org.abstractj.kalium.crypto.Random; import org.abstractj.kalium.crypto.Util; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.slice; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class SigningKey { private final byte[] seed; private final byte[] secretKey; private final VerifyKey verifyKey; public SigningKey(byte[] seed) { checkLength(seed, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.seed = seed; this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES * 2); byte[] publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES);
// Path: src/main/java/org/abstractj/kalium/crypto/Random.java // public class Random { // // private static final int DEFAULT_SIZE = 32; // // /** // * Generate random bytes // * // * @param n number or random bytes // * @return // */ // public byte[] randomBytes(int n) { // byte[] buffer = new byte[n]; // sodium().randombytes(buffer, n); // return buffer; // } // // public byte[] randomBytes() { // byte[] buffer = new byte[DEFAULT_SIZE]; // sodium().randombytes(buffer, DEFAULT_SIZE); // return buffer; // } // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public class Util { // // private static final int DEFAULT_SIZE = 32; // // public static byte[] prependZeros(int n, byte[] message) { // byte[] result = new byte[n + message.length]; // System.arraycopy(message, 0, result, n, message.length); // return result; // } // // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // public static byte[] zeros(int n) { // return new byte[n]; // } // // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // public static byte[] merge(byte[] signature, byte[] message) { // byte[] result = new byte[signature.length + message.length]; // System.arraycopy(signature, 0, result, 0, signature.length); // System.arraycopy(message, 0, result, signature.length, message.length); // return result; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/keys/SigningKey.java import jnr.ffi.byref.LongLongByReference; import org.abstractj.kalium.crypto.Random; import org.abstractj.kalium.crypto.Util; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.slice; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class SigningKey { private final byte[] seed; private final byte[] secretKey; private final VerifyKey verifyKey; public SigningKey(byte[] seed) { checkLength(seed, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.seed = seed; this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES * 2); byte[] publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES);
isValid(sodium().crypto_sign_ed25519_seed_keypair(publicKey, secretKey, seed),
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/SigningKey.java
// Path: src/main/java/org/abstractj/kalium/crypto/Random.java // public class Random { // // private static final int DEFAULT_SIZE = 32; // // /** // * Generate random bytes // * // * @param n number or random bytes // * @return // */ // public byte[] randomBytes(int n) { // byte[] buffer = new byte[n]; // sodium().randombytes(buffer, n); // return buffer; // } // // public byte[] randomBytes() { // byte[] buffer = new byte[DEFAULT_SIZE]; // sodium().randombytes(buffer, DEFAULT_SIZE); // return buffer; // } // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public class Util { // // private static final int DEFAULT_SIZE = 32; // // public static byte[] prependZeros(int n, byte[] message) { // byte[] result = new byte[n + message.length]; // System.arraycopy(message, 0, result, n, message.length); // return result; // } // // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // public static byte[] zeros(int n) { // return new byte[n]; // } // // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // public static byte[] merge(byte[] signature, byte[] message) { // byte[] result = new byte[signature.length + message.length]; // System.arraycopy(signature, 0, result, 0, signature.length); // System.arraycopy(message, 0, result, signature.length, message.length); // return result; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import jnr.ffi.byref.LongLongByReference; import org.abstractj.kalium.crypto.Random; import org.abstractj.kalium.crypto.Util; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.slice; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class SigningKey { private final byte[] seed; private final byte[] secretKey; private final VerifyKey verifyKey; public SigningKey(byte[] seed) { checkLength(seed, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.seed = seed; this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES * 2); byte[] publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); isValid(sodium().crypto_sign_ed25519_seed_keypair(publicKey, secretKey, seed), "Failed to generate a key pair"); this.verifyKey = new VerifyKey(publicKey); } public SigningKey() {
// Path: src/main/java/org/abstractj/kalium/crypto/Random.java // public class Random { // // private static final int DEFAULT_SIZE = 32; // // /** // * Generate random bytes // * // * @param n number or random bytes // * @return // */ // public byte[] randomBytes(int n) { // byte[] buffer = new byte[n]; // sodium().randombytes(buffer, n); // return buffer; // } // // public byte[] randomBytes() { // byte[] buffer = new byte[DEFAULT_SIZE]; // sodium().randombytes(buffer, DEFAULT_SIZE); // return buffer; // } // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public class Util { // // private static final int DEFAULT_SIZE = 32; // // public static byte[] prependZeros(int n, byte[] message) { // byte[] result = new byte[n + message.length]; // System.arraycopy(message, 0, result, n, message.length); // return result; // } // // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // public static byte[] zeros(int n) { // return new byte[n]; // } // // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // public static byte[] merge(byte[] signature, byte[] message) { // byte[] result = new byte[signature.length + message.length]; // System.arraycopy(signature, 0, result, 0, signature.length); // System.arraycopy(message, 0, result, signature.length, message.length); // return result; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/keys/SigningKey.java import jnr.ffi.byref.LongLongByReference; import org.abstractj.kalium.crypto.Random; import org.abstractj.kalium.crypto.Util; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.slice; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class SigningKey { private final byte[] seed; private final byte[] secretKey; private final VerifyKey verifyKey; public SigningKey(byte[] seed) { checkLength(seed, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.seed = seed; this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES * 2); byte[] publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); isValid(sodium().crypto_sign_ed25519_seed_keypair(publicKey, secretKey, seed), "Failed to generate a key pair"); this.verifyKey = new VerifyKey(publicKey); } public SigningKey() {
this(new Random().randomBytes(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES));
abstractj/kalium
src/main/java/org/abstractj/kalium/keys/SigningKey.java
// Path: src/main/java/org/abstractj/kalium/crypto/Random.java // public class Random { // // private static final int DEFAULT_SIZE = 32; // // /** // * Generate random bytes // * // * @param n number or random bytes // * @return // */ // public byte[] randomBytes(int n) { // byte[] buffer = new byte[n]; // sodium().randombytes(buffer, n); // return buffer; // } // // public byte[] randomBytes() { // byte[] buffer = new byte[DEFAULT_SIZE]; // sodium().randombytes(buffer, DEFAULT_SIZE); // return buffer; // } // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public class Util { // // private static final int DEFAULT_SIZE = 32; // // public static byte[] prependZeros(int n, byte[] message) { // byte[] result = new byte[n + message.length]; // System.arraycopy(message, 0, result, n, message.length); // return result; // } // // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // public static byte[] zeros(int n) { // return new byte[n]; // } // // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // public static byte[] merge(byte[] signature, byte[] message) { // byte[] result = new byte[signature.length + message.length]; // System.arraycopy(signature, 0, result, 0, signature.length); // System.arraycopy(message, 0, result, signature.length, message.length); // return result; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // }
import jnr.ffi.byref.LongLongByReference; import org.abstractj.kalium.crypto.Random; import org.abstractj.kalium.crypto.Util; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.slice; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class SigningKey { private final byte[] seed; private final byte[] secretKey; private final VerifyKey verifyKey; public SigningKey(byte[] seed) { checkLength(seed, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.seed = seed; this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES * 2); byte[] publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); isValid(sodium().crypto_sign_ed25519_seed_keypair(publicKey, secretKey, seed), "Failed to generate a key pair"); this.verifyKey = new VerifyKey(publicKey); } public SigningKey() { this(new Random().randomBytes(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES)); }
// Path: src/main/java/org/abstractj/kalium/crypto/Random.java // public class Random { // // private static final int DEFAULT_SIZE = 32; // // /** // * Generate random bytes // * // * @param n number or random bytes // * @return // */ // public byte[] randomBytes(int n) { // byte[] buffer = new byte[n]; // sodium().randombytes(buffer, n); // return buffer; // } // // public byte[] randomBytes() { // byte[] buffer = new byte[DEFAULT_SIZE]; // sodium().randombytes(buffer, DEFAULT_SIZE); // return buffer; // } // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public class Util { // // private static final int DEFAULT_SIZE = 32; // // public static byte[] prependZeros(int n, byte[] message) { // byte[] result = new byte[n + message.length]; // System.arraycopy(message, 0, result, n, message.length); // return result; // } // // public static byte[] removeZeros(int n, byte[] message) { // return Arrays.copyOfRange(message, n, message.length); // } // // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // public static byte[] zeros(int n) { // return new byte[n]; // } // // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // public static byte[] merge(byte[] signature, byte[] message) { // byte[] result = new byte[signature.length + message.length]; // System.arraycopy(signature, 0, result, 0, signature.length); // System.arraycopy(message, 0, result, signature.length, message.length); // return result; // } // } // // Path: src/main/java/org/abstractj/kalium/encoders/Encoder.java // public interface Encoder { // // public static final Charset CHARSET = Charset.forName("US-ASCII"); // // public static final Hex HEX = new Hex(); // public static final Raw RAW = new Raw(); // // public byte[] decode(String data); // // public String encode(final byte[] data); // } // // Path: src/main/java/org/abstractj/kalium/NaCl.java // public static Sodium sodium() { // Sodium sodium = SingletonHolder.SODIUM_INSTANCE; // checkVersion(sodium); // return sodium; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static void checkLength(byte[] data, int size) { // if (data == null || data.length != size) // throw new RuntimeException("Invalid size"); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static boolean isValid(int status, String message) { // if (status != 0) // throw new RuntimeException(message); // return true; // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] slice(byte[] buffer, int start, int end) { // return Arrays.copyOfRange(buffer, start, end); // } // // Path: src/main/java/org/abstractj/kalium/crypto/Util.java // public static byte[] zeros(int n) { // return new byte[n]; // } // Path: src/main/java/org/abstractj/kalium/keys/SigningKey.java import jnr.ffi.byref.LongLongByReference; import org.abstractj.kalium.crypto.Random; import org.abstractj.kalium.crypto.Util; import org.abstractj.kalium.encoders.Encoder; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES; import static org.abstractj.kalium.NaCl.Sodium.CRYPTO_SIGN_ED25519_BYTES; import static org.abstractj.kalium.NaCl.sodium; import static org.abstractj.kalium.crypto.Util.checkLength; import static org.abstractj.kalium.crypto.Util.isValid; import static org.abstractj.kalium.crypto.Util.slice; import static org.abstractj.kalium.crypto.Util.zeros; import static org.abstractj.kalium.encoders.Encoder.HEX; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class SigningKey { private final byte[] seed; private final byte[] secretKey; private final VerifyKey verifyKey; public SigningKey(byte[] seed) { checkLength(seed, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES); this.seed = seed; this.secretKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES * 2); byte[] publicKey = zeros(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES); isValid(sodium().crypto_sign_ed25519_seed_keypair(publicKey, secretKey, seed), "Failed to generate a key pair"); this.verifyKey = new VerifyKey(publicKey); } public SigningKey() { this(new Random().randomBytes(CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES)); }
public SigningKey(String seed, Encoder encoder) {
abstractj/kalium
src/test/java/org/abstractj/kalium/keys/VerifyKeyTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_MESSAGE = "916c7d1d268fc0e77c1bef238432573c39be577bbea0998936add2b50a653171" + // "ce18a542b0b7f96c1691a3be6031522894a8634183eda38798a0c5d5d79fbd01" + // "dd04a8646d71873b77b221998a81922d8105f892316369d5224c9983372d2313" + // "c6b1f4556ea26ba49d46e8b561e0fc76633ac9766e68e21fba7edca93c4c7460" + // "376d7f3ac22ff372c18f613f2ae2e856af40"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PRIVATE = "b18e1d0045995ec3d010c387ccfeb984d783af8fbb0f40fa7db126d889f6dadd"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PUBLIC = "77f48b59caeda77751ed138b0ec667ff50f8768c25d48309a8f386a2bad187fb"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_SIGNATURE = "6bd710a368c1249923fc7a1610747403040f0cc30815a00f9ff548a896bbda0b" + // "4eb2ca19ebcf917f0f34200a9edbad3901b64ab09cc5ef7b9bcc3c40c0ff7509";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIGN_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PRIVATE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PUBLIC; import static org.abstractj.kalium.fixture.TestVectors.SIGN_SIGNATURE; import static org.junit.Assert.fail;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKeyTest { @Test public void testVerifyCorrectRawSignature() throws Exception {
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_MESSAGE = "916c7d1d268fc0e77c1bef238432573c39be577bbea0998936add2b50a653171" + // "ce18a542b0b7f96c1691a3be6031522894a8634183eda38798a0c5d5d79fbd01" + // "dd04a8646d71873b77b221998a81922d8105f892316369d5224c9983372d2313" + // "c6b1f4556ea26ba49d46e8b561e0fc76633ac9766e68e21fba7edca93c4c7460" + // "376d7f3ac22ff372c18f613f2ae2e856af40"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PRIVATE = "b18e1d0045995ec3d010c387ccfeb984d783af8fbb0f40fa7db126d889f6dadd"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PUBLIC = "77f48b59caeda77751ed138b0ec667ff50f8768c25d48309a8f386a2bad187fb"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_SIGNATURE = "6bd710a368c1249923fc7a1610747403040f0cc30815a00f9ff548a896bbda0b" + // "4eb2ca19ebcf917f0f34200a9edbad3901b64ab09cc5ef7b9bcc3c40c0ff7509"; // Path: src/test/java/org/abstractj/kalium/keys/VerifyKeyTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIGN_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PRIVATE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PUBLIC; import static org.abstractj.kalium.fixture.TestVectors.SIGN_SIGNATURE; import static org.junit.Assert.fail; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKeyTest { @Test public void testVerifyCorrectRawSignature() throws Exception {
byte[] rawSignature = HEX.decode(SIGN_SIGNATURE);
abstractj/kalium
src/test/java/org/abstractj/kalium/keys/VerifyKeyTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_MESSAGE = "916c7d1d268fc0e77c1bef238432573c39be577bbea0998936add2b50a653171" + // "ce18a542b0b7f96c1691a3be6031522894a8634183eda38798a0c5d5d79fbd01" + // "dd04a8646d71873b77b221998a81922d8105f892316369d5224c9983372d2313" + // "c6b1f4556ea26ba49d46e8b561e0fc76633ac9766e68e21fba7edca93c4c7460" + // "376d7f3ac22ff372c18f613f2ae2e856af40"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PRIVATE = "b18e1d0045995ec3d010c387ccfeb984d783af8fbb0f40fa7db126d889f6dadd"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PUBLIC = "77f48b59caeda77751ed138b0ec667ff50f8768c25d48309a8f386a2bad187fb"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_SIGNATURE = "6bd710a368c1249923fc7a1610747403040f0cc30815a00f9ff548a896bbda0b" + // "4eb2ca19ebcf917f0f34200a9edbad3901b64ab09cc5ef7b9bcc3c40c0ff7509";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIGN_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PRIVATE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PUBLIC; import static org.abstractj.kalium.fixture.TestVectors.SIGN_SIGNATURE; import static org.junit.Assert.fail;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKeyTest { @Test public void testVerifyCorrectRawSignature() throws Exception { byte[] rawSignature = HEX.decode(SIGN_SIGNATURE);
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_MESSAGE = "916c7d1d268fc0e77c1bef238432573c39be577bbea0998936add2b50a653171" + // "ce18a542b0b7f96c1691a3be6031522894a8634183eda38798a0c5d5d79fbd01" + // "dd04a8646d71873b77b221998a81922d8105f892316369d5224c9983372d2313" + // "c6b1f4556ea26ba49d46e8b561e0fc76633ac9766e68e21fba7edca93c4c7460" + // "376d7f3ac22ff372c18f613f2ae2e856af40"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PRIVATE = "b18e1d0045995ec3d010c387ccfeb984d783af8fbb0f40fa7db126d889f6dadd"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PUBLIC = "77f48b59caeda77751ed138b0ec667ff50f8768c25d48309a8f386a2bad187fb"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_SIGNATURE = "6bd710a368c1249923fc7a1610747403040f0cc30815a00f9ff548a896bbda0b" + // "4eb2ca19ebcf917f0f34200a9edbad3901b64ab09cc5ef7b9bcc3c40c0ff7509"; // Path: src/test/java/org/abstractj/kalium/keys/VerifyKeyTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIGN_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PRIVATE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PUBLIC; import static org.abstractj.kalium.fixture.TestVectors.SIGN_SIGNATURE; import static org.junit.Assert.fail; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKeyTest { @Test public void testVerifyCorrectRawSignature() throws Exception { byte[] rawSignature = HEX.decode(SIGN_SIGNATURE);
byte[] rawMessage = HEX.decode(SIGN_MESSAGE);
abstractj/kalium
src/test/java/org/abstractj/kalium/keys/VerifyKeyTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_MESSAGE = "916c7d1d268fc0e77c1bef238432573c39be577bbea0998936add2b50a653171" + // "ce18a542b0b7f96c1691a3be6031522894a8634183eda38798a0c5d5d79fbd01" + // "dd04a8646d71873b77b221998a81922d8105f892316369d5224c9983372d2313" + // "c6b1f4556ea26ba49d46e8b561e0fc76633ac9766e68e21fba7edca93c4c7460" + // "376d7f3ac22ff372c18f613f2ae2e856af40"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PRIVATE = "b18e1d0045995ec3d010c387ccfeb984d783af8fbb0f40fa7db126d889f6dadd"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PUBLIC = "77f48b59caeda77751ed138b0ec667ff50f8768c25d48309a8f386a2bad187fb"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_SIGNATURE = "6bd710a368c1249923fc7a1610747403040f0cc30815a00f9ff548a896bbda0b" + // "4eb2ca19ebcf917f0f34200a9edbad3901b64ab09cc5ef7b9bcc3c40c0ff7509";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIGN_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PRIVATE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PUBLIC; import static org.abstractj.kalium.fixture.TestVectors.SIGN_SIGNATURE; import static org.junit.Assert.fail;
/** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKeyTest { @Test public void testVerifyCorrectRawSignature() throws Exception { byte[] rawSignature = HEX.decode(SIGN_SIGNATURE); byte[] rawMessage = HEX.decode(SIGN_MESSAGE);
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_MESSAGE = "916c7d1d268fc0e77c1bef238432573c39be577bbea0998936add2b50a653171" + // "ce18a542b0b7f96c1691a3be6031522894a8634183eda38798a0c5d5d79fbd01" + // "dd04a8646d71873b77b221998a81922d8105f892316369d5224c9983372d2313" + // "c6b1f4556ea26ba49d46e8b561e0fc76633ac9766e68e21fba7edca93c4c7460" + // "376d7f3ac22ff372c18f613f2ae2e856af40"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PRIVATE = "b18e1d0045995ec3d010c387ccfeb984d783af8fbb0f40fa7db126d889f6dadd"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PUBLIC = "77f48b59caeda77751ed138b0ec667ff50f8768c25d48309a8f386a2bad187fb"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_SIGNATURE = "6bd710a368c1249923fc7a1610747403040f0cc30815a00f9ff548a896bbda0b" + // "4eb2ca19ebcf917f0f34200a9edbad3901b64ab09cc5ef7b9bcc3c40c0ff7509"; // Path: src/test/java/org/abstractj/kalium/keys/VerifyKeyTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIGN_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PRIVATE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PUBLIC; import static org.abstractj.kalium.fixture.TestVectors.SIGN_SIGNATURE; import static org.junit.Assert.fail; /** * Copyright 2013 Bruno Oliveira, and individual contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.abstractj.kalium.keys; public class VerifyKeyTest { @Test public void testVerifyCorrectRawSignature() throws Exception { byte[] rawSignature = HEX.decode(SIGN_SIGNATURE); byte[] rawMessage = HEX.decode(SIGN_MESSAGE);
byte[] rawPublicKey = HEX.decode(SIGN_PUBLIC);
abstractj/kalium
src/test/java/org/abstractj/kalium/keys/VerifyKeyTest.java
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_MESSAGE = "916c7d1d268fc0e77c1bef238432573c39be577bbea0998936add2b50a653171" + // "ce18a542b0b7f96c1691a3be6031522894a8634183eda38798a0c5d5d79fbd01" + // "dd04a8646d71873b77b221998a81922d8105f892316369d5224c9983372d2313" + // "c6b1f4556ea26ba49d46e8b561e0fc76633ac9766e68e21fba7edca93c4c7460" + // "376d7f3ac22ff372c18f613f2ae2e856af40"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PRIVATE = "b18e1d0045995ec3d010c387ccfeb984d783af8fbb0f40fa7db126d889f6dadd"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PUBLIC = "77f48b59caeda77751ed138b0ec667ff50f8768c25d48309a8f386a2bad187fb"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_SIGNATURE = "6bd710a368c1249923fc7a1610747403040f0cc30815a00f9ff548a896bbda0b" + // "4eb2ca19ebcf917f0f34200a9edbad3901b64ab09cc5ef7b9bcc3c40c0ff7509";
import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIGN_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PRIVATE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PUBLIC; import static org.abstractj.kalium.fixture.TestVectors.SIGN_SIGNATURE; import static org.junit.Assert.fail;
@Test public void testVerifyCorrectHexSignature() throws Exception { byte[] rawPublicKey = HEX.decode(SIGN_PUBLIC); VerifyKey verifyKey = new VerifyKey(rawPublicKey); verifyKey.verify(SIGN_MESSAGE, SIGN_SIGNATURE, HEX); assertTrue(verifyKey.verify(SIGN_MESSAGE, SIGN_SIGNATURE, HEX)); } @Test public void testDetectBadSignature() throws Exception { try { String badSignature = SIGN_SIGNATURE.concat("0000"); VerifyKey verifyKey = new VerifyKey(SIGN_PUBLIC, HEX); verifyKey.verify(SIGN_MESSAGE, badSignature, HEX); fail("Should an exception on bad signatures"); } catch (Exception e) { assertTrue(true); } } @Test public void testSerializeToBytes() throws Exception { byte[] rawPublic = HEX.decode(SIGN_PUBLIC); VerifyKey verifyKey = new VerifyKey(SIGN_PUBLIC, HEX); verifyKey.verify(SIGN_MESSAGE, SIGN_SIGNATURE, HEX); assertTrue(Arrays.equals(verifyKey.toBytes(), rawPublic)); } @Test public void testSerializeToString() throws Exception {
// Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_MESSAGE = "916c7d1d268fc0e77c1bef238432573c39be577bbea0998936add2b50a653171" + // "ce18a542b0b7f96c1691a3be6031522894a8634183eda38798a0c5d5d79fbd01" + // "dd04a8646d71873b77b221998a81922d8105f892316369d5224c9983372d2313" + // "c6b1f4556ea26ba49d46e8b561e0fc76633ac9766e68e21fba7edca93c4c7460" + // "376d7f3ac22ff372c18f613f2ae2e856af40"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PRIVATE = "b18e1d0045995ec3d010c387ccfeb984d783af8fbb0f40fa7db126d889f6dadd"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_PUBLIC = "77f48b59caeda77751ed138b0ec667ff50f8768c25d48309a8f386a2bad187fb"; // // Path: src/test/java/org/abstractj/kalium/fixture/TestVectors.java // public static final String SIGN_SIGNATURE = "6bd710a368c1249923fc7a1610747403040f0cc30815a00f9ff548a896bbda0b" + // "4eb2ca19ebcf917f0f34200a9edbad3901b64ab09cc5ef7b9bcc3c40c0ff7509"; // Path: src/test/java/org/abstractj/kalium/keys/VerifyKeyTest.java import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.abstractj.kalium.encoders.Encoder.HEX; import static org.abstractj.kalium.fixture.TestVectors.SIGN_MESSAGE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PRIVATE; import static org.abstractj.kalium.fixture.TestVectors.SIGN_PUBLIC; import static org.abstractj.kalium.fixture.TestVectors.SIGN_SIGNATURE; import static org.junit.Assert.fail; @Test public void testVerifyCorrectHexSignature() throws Exception { byte[] rawPublicKey = HEX.decode(SIGN_PUBLIC); VerifyKey verifyKey = new VerifyKey(rawPublicKey); verifyKey.verify(SIGN_MESSAGE, SIGN_SIGNATURE, HEX); assertTrue(verifyKey.verify(SIGN_MESSAGE, SIGN_SIGNATURE, HEX)); } @Test public void testDetectBadSignature() throws Exception { try { String badSignature = SIGN_SIGNATURE.concat("0000"); VerifyKey verifyKey = new VerifyKey(SIGN_PUBLIC, HEX); verifyKey.verify(SIGN_MESSAGE, badSignature, HEX); fail("Should an exception on bad signatures"); } catch (Exception e) { assertTrue(true); } } @Test public void testSerializeToBytes() throws Exception { byte[] rawPublic = HEX.decode(SIGN_PUBLIC); VerifyKey verifyKey = new VerifyKey(SIGN_PUBLIC, HEX); verifyKey.verify(SIGN_MESSAGE, SIGN_SIGNATURE, HEX); assertTrue(Arrays.equals(verifyKey.toBytes(), rawPublic)); } @Test public void testSerializeToString() throws Exception {
SigningKey key = new SigningKey(SIGN_PRIVATE, HEX);
Nedelosk/OreRegistry
src/main/java/oreregistry/integration/JeiPlugin.java
// Path: src/main/java/oreregistry/OreRegistry.java // @Mod(modid = Constants.MOD_ID, name = Constants.NAME, version = Constants.VERSION, acceptedMinecraftVersions = "[1.11]") // public class OreRegistry { // // @Nullable // @Mod.Instance(Constants.MOD_ID) // public static OreRegistry instance; // // public static final ResourceRegistry registry; // public static final ResourceInfo helper; // public static final List<ItemStack> unusedItems = new ArrayList<>(); // @Nullable // public static File configFile; // // static { // OreRegistryApi.registry = registry = new ResourceRegistry(); // OreRegistryApi.info = helper = new ResourceInfo(); // } // // @Mod.EventHandler // public void preInit(FMLPreInitializationEvent event) { // registerVanilla(OreRegistryApi.registry); // MinecraftForge.EVENT_BUS.register(new EventHandler()); // new PacketHandler(); // configFile = event.getSuggestedConfigurationFile(); // } // // @Mod.EventHandler // public void init(FMLInitializationEvent event) { // Config.load(event.getSide()); // } // // private void registerVanilla(IResourceRegistry resourceRegistry) { // final IResource iron = resourceRegistry.registerResource(ResourceTypes.IRON); // iron.registerProduct(INGOT, new ItemStack(Items.IRON_INGOT)); // iron.registerProduct(NUGGET, new ItemStack(Items.field_191525_da)); // iron.registerProduct(BLOCK, new ItemStack(Blocks.IRON_BLOCK)); // iron.registerProduct(ORE, new ItemStack(Blocks.IRON_ORE)); // // final IResource gold = resourceRegistry.registerResource(ResourceTypes.GOLD); // gold.registerProduct(INGOT, new ItemStack(Items.GOLD_INGOT)); // gold.registerProduct(NUGGET, new ItemStack(Items.GOLD_NUGGET)); // gold.registerProduct(BLOCK, new ItemStack(Blocks.GOLD_BLOCK)); // gold.registerProduct(ORE, new ItemStack(Blocks.GOLD_ORE)); // // final IResource emerald = resourceRegistry.registerResource(ResourceTypes.EMERALD); // emerald.registerProduct(GEM, new ItemStack(Items.EMERALD)); // emerald.registerProduct(BLOCK, new ItemStack(Blocks.EMERALD_BLOCK)); // emerald.registerProduct(ORE, new ItemStack(Blocks.EMERALD_ORE)); // // final IResource diamond = resourceRegistry.registerResource(ResourceTypes.DIAMOND); // diamond.registerProduct(GEM, new ItemStack(Items.DIAMOND)); // diamond.registerProduct(BLOCK, new ItemStack(Blocks.DIAMOND_BLOCK)); // diamond.registerProduct(ORE, new ItemStack(Blocks.DIAMOND_ORE)); // // final IResource lapis = resourceRegistry.registerResource(ResourceTypes.LAPIS); // lapis.registerProduct(GEM, new ItemStack(Items.DYE, 1, EnumDyeColor.BLUE.getDyeDamage())); // lapis.registerProduct(BLOCK, new ItemStack(Blocks.LAPIS_BLOCK)); // lapis.registerProduct(ORE, new ItemStack(Blocks.LAPIS_ORE)); // // final IResource redstone = resourceRegistry.registerResource(ResourceTypes.REDSTONE); // redstone.registerProduct(DUST, new ItemStack(Items.REDSTONE)); // redstone.registerProduct(BLOCK, new ItemStack(Blocks.REDSTONE_BLOCK)); // redstone.registerProduct(ORE, new ItemStack(Blocks.REDSTONE_ORE)); // // final IResource quartz = resourceRegistry.registerResource(ResourceTypes.QUARTZ); // quartz.registerProduct(GEM, new ItemStack(Items.QUARTZ)); // quartz.registerProduct(BLOCK, new ItemStack(Blocks.QUARTZ_BLOCK)); // quartz.registerProduct(ORE, new ItemStack(Blocks.QUARTZ_ORE)); // // final IResource coal = resourceRegistry.registerResource(ResourceTypes.COAL); // coal.registerProduct(GEM, new ItemStack(Items.COAL)); // coal.registerProduct(BLOCK, new ItemStack(Blocks.COAL_BLOCK)); // coal.registerProduct(ORE, new ItemStack(Blocks.COAL_ORE)); // } // // public File getConfigFile(){ // return configFile; // } // }
import mezz.jei.api.BlankModPlugin; import mezz.jei.api.IModRegistry; import mezz.jei.api.JEIPlugin; import mezz.jei.api.ingredients.IIngredientBlacklist; import net.minecraft.item.ItemStack; import oreregistry.OreRegistry;
/* * Copyright (c) 2017 Nedelosk, Mezz * * This work (the MOD) is licensed under the "MIT" License, see LICENSE for details. */ package oreregistry.integration; @JEIPlugin public class JeiPlugin extends BlankModPlugin { @Override public void register(IModRegistry registry) { IIngredientBlacklist ingredientBlacklist = registry.getJeiHelpers().getIngredientBlacklist();
// Path: src/main/java/oreregistry/OreRegistry.java // @Mod(modid = Constants.MOD_ID, name = Constants.NAME, version = Constants.VERSION, acceptedMinecraftVersions = "[1.11]") // public class OreRegistry { // // @Nullable // @Mod.Instance(Constants.MOD_ID) // public static OreRegistry instance; // // public static final ResourceRegistry registry; // public static final ResourceInfo helper; // public static final List<ItemStack> unusedItems = new ArrayList<>(); // @Nullable // public static File configFile; // // static { // OreRegistryApi.registry = registry = new ResourceRegistry(); // OreRegistryApi.info = helper = new ResourceInfo(); // } // // @Mod.EventHandler // public void preInit(FMLPreInitializationEvent event) { // registerVanilla(OreRegistryApi.registry); // MinecraftForge.EVENT_BUS.register(new EventHandler()); // new PacketHandler(); // configFile = event.getSuggestedConfigurationFile(); // } // // @Mod.EventHandler // public void init(FMLInitializationEvent event) { // Config.load(event.getSide()); // } // // private void registerVanilla(IResourceRegistry resourceRegistry) { // final IResource iron = resourceRegistry.registerResource(ResourceTypes.IRON); // iron.registerProduct(INGOT, new ItemStack(Items.IRON_INGOT)); // iron.registerProduct(NUGGET, new ItemStack(Items.field_191525_da)); // iron.registerProduct(BLOCK, new ItemStack(Blocks.IRON_BLOCK)); // iron.registerProduct(ORE, new ItemStack(Blocks.IRON_ORE)); // // final IResource gold = resourceRegistry.registerResource(ResourceTypes.GOLD); // gold.registerProduct(INGOT, new ItemStack(Items.GOLD_INGOT)); // gold.registerProduct(NUGGET, new ItemStack(Items.GOLD_NUGGET)); // gold.registerProduct(BLOCK, new ItemStack(Blocks.GOLD_BLOCK)); // gold.registerProduct(ORE, new ItemStack(Blocks.GOLD_ORE)); // // final IResource emerald = resourceRegistry.registerResource(ResourceTypes.EMERALD); // emerald.registerProduct(GEM, new ItemStack(Items.EMERALD)); // emerald.registerProduct(BLOCK, new ItemStack(Blocks.EMERALD_BLOCK)); // emerald.registerProduct(ORE, new ItemStack(Blocks.EMERALD_ORE)); // // final IResource diamond = resourceRegistry.registerResource(ResourceTypes.DIAMOND); // diamond.registerProduct(GEM, new ItemStack(Items.DIAMOND)); // diamond.registerProduct(BLOCK, new ItemStack(Blocks.DIAMOND_BLOCK)); // diamond.registerProduct(ORE, new ItemStack(Blocks.DIAMOND_ORE)); // // final IResource lapis = resourceRegistry.registerResource(ResourceTypes.LAPIS); // lapis.registerProduct(GEM, new ItemStack(Items.DYE, 1, EnumDyeColor.BLUE.getDyeDamage())); // lapis.registerProduct(BLOCK, new ItemStack(Blocks.LAPIS_BLOCK)); // lapis.registerProduct(ORE, new ItemStack(Blocks.LAPIS_ORE)); // // final IResource redstone = resourceRegistry.registerResource(ResourceTypes.REDSTONE); // redstone.registerProduct(DUST, new ItemStack(Items.REDSTONE)); // redstone.registerProduct(BLOCK, new ItemStack(Blocks.REDSTONE_BLOCK)); // redstone.registerProduct(ORE, new ItemStack(Blocks.REDSTONE_ORE)); // // final IResource quartz = resourceRegistry.registerResource(ResourceTypes.QUARTZ); // quartz.registerProduct(GEM, new ItemStack(Items.QUARTZ)); // quartz.registerProduct(BLOCK, new ItemStack(Blocks.QUARTZ_BLOCK)); // quartz.registerProduct(ORE, new ItemStack(Blocks.QUARTZ_ORE)); // // final IResource coal = resourceRegistry.registerResource(ResourceTypes.COAL); // coal.registerProduct(GEM, new ItemStack(Items.COAL)); // coal.registerProduct(BLOCK, new ItemStack(Blocks.COAL_BLOCK)); // coal.registerProduct(ORE, new ItemStack(Blocks.COAL_ORE)); // } // // public File getConfigFile(){ // return configFile; // } // } // Path: src/main/java/oreregistry/integration/JeiPlugin.java import mezz.jei.api.BlankModPlugin; import mezz.jei.api.IModRegistry; import mezz.jei.api.JEIPlugin; import mezz.jei.api.ingredients.IIngredientBlacklist; import net.minecraft.item.ItemStack; import oreregistry.OreRegistry; /* * Copyright (c) 2017 Nedelosk, Mezz * * This work (the MOD) is licensed under the "MIT" License, see LICENSE for details. */ package oreregistry.integration; @JEIPlugin public class JeiPlugin extends BlankModPlugin { @Override public void register(IModRegistry registry) { IIngredientBlacklist ingredientBlacklist = registry.getJeiHelpers().getIngredientBlacklist();
for (ItemStack itemStack : OreRegistry.unusedItems) {
Nedelosk/OreRegistry
src/main/java/oreregistry/util/ResourceRegistry.java
// Path: src/main/java/oreregistry/api/IUnificationHandler.java // @FunctionalInterface // public interface IUnificationHandler { // // void onUnifyItem(ItemStack oldStack, ItemStack newStack, IProduct product); // } // // Path: src/main/java/oreregistry/api/OreRegistryState.java // public enum OreRegistryState { // /** // * This state is active if in the pre init phase of fml. // */ // ACTIVE, // /** // * This state is always active after the pre init phase of fml except the mod chooses currently his products or its currently synchronises with the server. // */ // INACTIVE, // /** // * This state is active if the client currently synchronises with the server. // */ // SYNCHRONIZE, // /** // * This state is active if the mod currently chooses the products. // */ // CHOOSE // // } // // Path: src/main/java/oreregistry/api/registry/IResource.java // public interface IResource { // // /** // * The type of the resource. For examples see {@link ResourceTypes}. // */ // String getType(); // // /** // * Register a product added by your mod for this resource. // * // * @param productType The type of the product. For examples see {@link ProductTypes}. // * @param product The product provided by your mod. // * @return the product that should be used by every mod. // */ // IProduct registerProduct(String productType, ItemStack product); // // /** // * // * @param productType The type of the product. For examples see {@link ProductTypes}. // * @return True if it is already a product registered with this type. // */ // boolean hasProduct(String productType); // // /** // * @param productType The type of the product. For examples see {@link ProductTypes}. // * @return The product of the productType, if one is registered. // */ // @Nullable // IProduct getProduct(String productType); // // /** // * Returns a read-only map containing product types and their associated products. // */ // Map<String, IProduct> getRegisteredProducts(); // // } // // Path: src/main/java/oreregistry/api/registry/IResourceRegistry.java // public interface IResourceRegistry { // // /** // * Register a type of resource added by your mod. // */ // IResource registerResource(String resourceType); // // /** // * Returns a read-only map containing resource names and their associated // * resources. // */ // Map<String, IResource> getRegisteredResources(); // // /** // * Register a {@link IUnificationHandler}. // */ // void registerUnificationHandler(String resourceType, IUnificationHandler unificationHandler); // // /** // * Returns a read-only map containing all {@link IUnificationHandler}s of the resource of this type. // */ // Collection<IUnificationHandler> getUnificationHandlers(String resourceType); // // /** // * The current state of the registry process. // * // * You only can register resources and products in the active state. // */ // OreRegistryState getState(); // // }
import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import javax.annotation.Nullable; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import oreregistry.api.IUnificationHandler; import oreregistry.api.OreRegistryState; import oreregistry.api.registry.IResource; import oreregistry.api.registry.IResourceRegistry;
/* * Copyright (c) 2017 Nedelosk, Mezz * * This work (the MOD) is licensed under the "MIT" License, see LICENSE for details. */ package oreregistry.util; public final class ResourceRegistry implements IResourceRegistry { private final Map<String, IResource> resources = new HashMap<>();
// Path: src/main/java/oreregistry/api/IUnificationHandler.java // @FunctionalInterface // public interface IUnificationHandler { // // void onUnifyItem(ItemStack oldStack, ItemStack newStack, IProduct product); // } // // Path: src/main/java/oreregistry/api/OreRegistryState.java // public enum OreRegistryState { // /** // * This state is active if in the pre init phase of fml. // */ // ACTIVE, // /** // * This state is always active after the pre init phase of fml except the mod chooses currently his products or its currently synchronises with the server. // */ // INACTIVE, // /** // * This state is active if the client currently synchronises with the server. // */ // SYNCHRONIZE, // /** // * This state is active if the mod currently chooses the products. // */ // CHOOSE // // } // // Path: src/main/java/oreregistry/api/registry/IResource.java // public interface IResource { // // /** // * The type of the resource. For examples see {@link ResourceTypes}. // */ // String getType(); // // /** // * Register a product added by your mod for this resource. // * // * @param productType The type of the product. For examples see {@link ProductTypes}. // * @param product The product provided by your mod. // * @return the product that should be used by every mod. // */ // IProduct registerProduct(String productType, ItemStack product); // // /** // * // * @param productType The type of the product. For examples see {@link ProductTypes}. // * @return True if it is already a product registered with this type. // */ // boolean hasProduct(String productType); // // /** // * @param productType The type of the product. For examples see {@link ProductTypes}. // * @return The product of the productType, if one is registered. // */ // @Nullable // IProduct getProduct(String productType); // // /** // * Returns a read-only map containing product types and their associated products. // */ // Map<String, IProduct> getRegisteredProducts(); // // } // // Path: src/main/java/oreregistry/api/registry/IResourceRegistry.java // public interface IResourceRegistry { // // /** // * Register a type of resource added by your mod. // */ // IResource registerResource(String resourceType); // // /** // * Returns a read-only map containing resource names and their associated // * resources. // */ // Map<String, IResource> getRegisteredResources(); // // /** // * Register a {@link IUnificationHandler}. // */ // void registerUnificationHandler(String resourceType, IUnificationHandler unificationHandler); // // /** // * Returns a read-only map containing all {@link IUnificationHandler}s of the resource of this type. // */ // Collection<IUnificationHandler> getUnificationHandlers(String resourceType); // // /** // * The current state of the registry process. // * // * You only can register resources and products in the active state. // */ // OreRegistryState getState(); // // } // Path: src/main/java/oreregistry/util/ResourceRegistry.java import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import javax.annotation.Nullable; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import oreregistry.api.IUnificationHandler; import oreregistry.api.OreRegistryState; import oreregistry.api.registry.IResource; import oreregistry.api.registry.IResourceRegistry; /* * Copyright (c) 2017 Nedelosk, Mezz * * This work (the MOD) is licensed under the "MIT" License, see LICENSE for details. */ package oreregistry.util; public final class ResourceRegistry implements IResourceRegistry { private final Map<String, IResource> resources = new HashMap<>();
private final Multimap<String, IUnificationHandler> unificationHandlers = HashMultimap.create();
Nedelosk/OreRegistry
src/main/java/oreregistry/util/ResourceRegistry.java
// Path: src/main/java/oreregistry/api/IUnificationHandler.java // @FunctionalInterface // public interface IUnificationHandler { // // void onUnifyItem(ItemStack oldStack, ItemStack newStack, IProduct product); // } // // Path: src/main/java/oreregistry/api/OreRegistryState.java // public enum OreRegistryState { // /** // * This state is active if in the pre init phase of fml. // */ // ACTIVE, // /** // * This state is always active after the pre init phase of fml except the mod chooses currently his products or its currently synchronises with the server. // */ // INACTIVE, // /** // * This state is active if the client currently synchronises with the server. // */ // SYNCHRONIZE, // /** // * This state is active if the mod currently chooses the products. // */ // CHOOSE // // } // // Path: src/main/java/oreregistry/api/registry/IResource.java // public interface IResource { // // /** // * The type of the resource. For examples see {@link ResourceTypes}. // */ // String getType(); // // /** // * Register a product added by your mod for this resource. // * // * @param productType The type of the product. For examples see {@link ProductTypes}. // * @param product The product provided by your mod. // * @return the product that should be used by every mod. // */ // IProduct registerProduct(String productType, ItemStack product); // // /** // * // * @param productType The type of the product. For examples see {@link ProductTypes}. // * @return True if it is already a product registered with this type. // */ // boolean hasProduct(String productType); // // /** // * @param productType The type of the product. For examples see {@link ProductTypes}. // * @return The product of the productType, if one is registered. // */ // @Nullable // IProduct getProduct(String productType); // // /** // * Returns a read-only map containing product types and their associated products. // */ // Map<String, IProduct> getRegisteredProducts(); // // } // // Path: src/main/java/oreregistry/api/registry/IResourceRegistry.java // public interface IResourceRegistry { // // /** // * Register a type of resource added by your mod. // */ // IResource registerResource(String resourceType); // // /** // * Returns a read-only map containing resource names and their associated // * resources. // */ // Map<String, IResource> getRegisteredResources(); // // /** // * Register a {@link IUnificationHandler}. // */ // void registerUnificationHandler(String resourceType, IUnificationHandler unificationHandler); // // /** // * Returns a read-only map containing all {@link IUnificationHandler}s of the resource of this type. // */ // Collection<IUnificationHandler> getUnificationHandlers(String resourceType); // // /** // * The current state of the registry process. // * // * You only can register resources and products in the active state. // */ // OreRegistryState getState(); // // }
import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import javax.annotation.Nullable; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import oreregistry.api.IUnificationHandler; import oreregistry.api.OreRegistryState; import oreregistry.api.registry.IResource; import oreregistry.api.registry.IResourceRegistry;
/* * Copyright (c) 2017 Nedelosk, Mezz * * This work (the MOD) is licensed under the "MIT" License, see LICENSE for details. */ package oreregistry.util; public final class ResourceRegistry implements IResourceRegistry { private final Map<String, IResource> resources = new HashMap<>(); private final Multimap<String, IUnificationHandler> unificationHandlers = HashMultimap.create();
// Path: src/main/java/oreregistry/api/IUnificationHandler.java // @FunctionalInterface // public interface IUnificationHandler { // // void onUnifyItem(ItemStack oldStack, ItemStack newStack, IProduct product); // } // // Path: src/main/java/oreregistry/api/OreRegistryState.java // public enum OreRegistryState { // /** // * This state is active if in the pre init phase of fml. // */ // ACTIVE, // /** // * This state is always active after the pre init phase of fml except the mod chooses currently his products or its currently synchronises with the server. // */ // INACTIVE, // /** // * This state is active if the client currently synchronises with the server. // */ // SYNCHRONIZE, // /** // * This state is active if the mod currently chooses the products. // */ // CHOOSE // // } // // Path: src/main/java/oreregistry/api/registry/IResource.java // public interface IResource { // // /** // * The type of the resource. For examples see {@link ResourceTypes}. // */ // String getType(); // // /** // * Register a product added by your mod for this resource. // * // * @param productType The type of the product. For examples see {@link ProductTypes}. // * @param product The product provided by your mod. // * @return the product that should be used by every mod. // */ // IProduct registerProduct(String productType, ItemStack product); // // /** // * // * @param productType The type of the product. For examples see {@link ProductTypes}. // * @return True if it is already a product registered with this type. // */ // boolean hasProduct(String productType); // // /** // * @param productType The type of the product. For examples see {@link ProductTypes}. // * @return The product of the productType, if one is registered. // */ // @Nullable // IProduct getProduct(String productType); // // /** // * Returns a read-only map containing product types and their associated products. // */ // Map<String, IProduct> getRegisteredProducts(); // // } // // Path: src/main/java/oreregistry/api/registry/IResourceRegistry.java // public interface IResourceRegistry { // // /** // * Register a type of resource added by your mod. // */ // IResource registerResource(String resourceType); // // /** // * Returns a read-only map containing resource names and their associated // * resources. // */ // Map<String, IResource> getRegisteredResources(); // // /** // * Register a {@link IUnificationHandler}. // */ // void registerUnificationHandler(String resourceType, IUnificationHandler unificationHandler); // // /** // * Returns a read-only map containing all {@link IUnificationHandler}s of the resource of this type. // */ // Collection<IUnificationHandler> getUnificationHandlers(String resourceType); // // /** // * The current state of the registry process. // * // * You only can register resources and products in the active state. // */ // OreRegistryState getState(); // // } // Path: src/main/java/oreregistry/util/ResourceRegistry.java import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import javax.annotation.Nullable; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import oreregistry.api.IUnificationHandler; import oreregistry.api.OreRegistryState; import oreregistry.api.registry.IResource; import oreregistry.api.registry.IResourceRegistry; /* * Copyright (c) 2017 Nedelosk, Mezz * * This work (the MOD) is licensed under the "MIT" License, see LICENSE for details. */ package oreregistry.util; public final class ResourceRegistry implements IResourceRegistry { private final Map<String, IResource> resources = new HashMap<>(); private final Multimap<String, IUnificationHandler> unificationHandlers = HashMultimap.create();
private OreRegistryState state;
Nedelosk/OreRegistry
src/main/java/oreregistry/api/OreRegistryApi.java
// Path: src/main/java/oreregistry/api/info/IResourceInfo.java // public interface IResourceInfo { // /** // * Get information about a registered product. // * Returns null if the product has not been registered. // */ // @Nullable // IProductInfo getProductInfo(ItemStack product); // // /** // * Tries to unify a item. // * <p> // * Returns an empty ItemStack if the item is already unified or if the item is not a variant of a registered product. // */ // ItemStack tryUnifyItem(ItemStack itemStack); // } // // Path: src/main/java/oreregistry/api/registry/IResourceRegistry.java // public interface IResourceRegistry { // // /** // * Register a type of resource added by your mod. // */ // IResource registerResource(String resourceType); // // /** // * Returns a read-only map containing resource names and their associated // * resources. // */ // Map<String, IResource> getRegisteredResources(); // // /** // * Register a {@link IUnificationHandler}. // */ // void registerUnificationHandler(String resourceType, IUnificationHandler unificationHandler); // // /** // * Returns a read-only map containing all {@link IUnificationHandler}s of the resource of this type. // */ // Collection<IUnificationHandler> getUnificationHandlers(String resourceType); // // /** // * The current state of the registry process. // * // * You only can register resources and products in the active state. // */ // OreRegistryState getState(); // // }
import oreregistry.api.registry.IResourceRegistry; import oreregistry.api.info.IResourceInfo;
/* * Copyright (c) 2017 Nedelosk, Mezz * * This work (the MOD) is licensed under the "MIT" License, see LICENSE for details. */ package oreregistry.api; public class OreRegistryApi { /** * Register resources and get the chosen resource for each type. */ public static IResourceRegistry registry; /** * Get information about registered products. */
// Path: src/main/java/oreregistry/api/info/IResourceInfo.java // public interface IResourceInfo { // /** // * Get information about a registered product. // * Returns null if the product has not been registered. // */ // @Nullable // IProductInfo getProductInfo(ItemStack product); // // /** // * Tries to unify a item. // * <p> // * Returns an empty ItemStack if the item is already unified or if the item is not a variant of a registered product. // */ // ItemStack tryUnifyItem(ItemStack itemStack); // } // // Path: src/main/java/oreregistry/api/registry/IResourceRegistry.java // public interface IResourceRegistry { // // /** // * Register a type of resource added by your mod. // */ // IResource registerResource(String resourceType); // // /** // * Returns a read-only map containing resource names and their associated // * resources. // */ // Map<String, IResource> getRegisteredResources(); // // /** // * Register a {@link IUnificationHandler}. // */ // void registerUnificationHandler(String resourceType, IUnificationHandler unificationHandler); // // /** // * Returns a read-only map containing all {@link IUnificationHandler}s of the resource of this type. // */ // Collection<IUnificationHandler> getUnificationHandlers(String resourceType); // // /** // * The current state of the registry process. // * // * You only can register resources and products in the active state. // */ // OreRegistryState getState(); // // } // Path: src/main/java/oreregistry/api/OreRegistryApi.java import oreregistry.api.registry.IResourceRegistry; import oreregistry.api.info.IResourceInfo; /* * Copyright (c) 2017 Nedelosk, Mezz * * This work (the MOD) is licensed under the "MIT" License, see LICENSE for details. */ package oreregistry.api; public class OreRegistryApi { /** * Register resources and get the chosen resource for each type. */ public static IResourceRegistry registry; /** * Get information about registered products. */
public static IResourceInfo info;