Search in sources :

Example 1 with PrintString

use of org.tomitribe.util.PrintString in project churchkey by tomitribe.

the class JsonAsserts method normalize.

private static String normalize(final String json) {
    final JsonReader reader = Json.createReader(IO.read(json));
    final JsonValue object = reader.readValue();
    final JsonValue jsonObject = sort(object);
    final Map<String, Object> properties = new HashMap<>(1);
    properties.put(JsonGenerator.PRETTY_PRINTING, true);
    final JsonGeneratorFactory jgf = Json.createGeneratorFactory(properties);
    final PrintString out = new PrintString();
    final JsonGenerator jg = jgf.createGenerator(out);
    jg.write(jsonObject);
    jg.flush();
    return out.toString();
}
Also used : PrintString(org.tomitribe.util.PrintString) HashMap(java.util.HashMap) JsonValue(javax.json.JsonValue) JsonReader(javax.json.JsonReader) JsonGenerator(javax.json.stream.JsonGenerator) JsonObject(javax.json.JsonObject) PrintString(org.tomitribe.util.PrintString) JsonGeneratorFactory(javax.json.stream.JsonGeneratorFactory)

Example 2 with PrintString

use of org.tomitribe.util.PrintString in project churchkey by tomitribe.

the class ECParameterSpecs method toString.

public static String toString(final ECParameterSpec spec) {
    final PrintString out = new PrintString();
    final String x = hex(spec.getGenerator().getAffineX());
    final String y = hex(spec.getGenerator().getAffineY());
    final String a = hex(spec.getCurve().getA());
    final String b = hex(spec.getCurve().getB());
    final String n = hex(spec.getOrder());
    final int cofactor = spec.getCofactor();
    final ECField field = spec.getCurve().getField();
    if (field instanceof ECFieldFp) {
        final ECFieldFp fp = (ECFieldFp) field;
        final String p = hex(fp.getP());
        out.printf("prime(\n" + "    \"%s\",\n" + "    \"%s\",\n" + "    \"%s\",\n" + "    \"%s\",\n" + "    \"%s\",\n" + "    \"%s\",\n" + "    %s), %s)\n", p, a, b, x, y, n, cofactor, null);
    } else if (field instanceof ECFieldF2m) {
        final ECFieldF2m binary = (ECFieldF2m) field;
        final int m = binary.getM();
        final List<Integer> terms = new ArrayList<>();
        for (final int i : binary.getMidTermsOfReductionPolynomial()) {
            terms.add(i);
        }
        out.printf("binary(%s, new int[]{%s},\n" + "    \"%s\",\n" + "    \"%s\",\n" + "    \"%s\",\n" + "    \"%s\",\n" + "    \"%s\",\n" + "    %s), %s)\n", m, Join.join(", ", terms), a, b, x, y, n, cofactor, null);
    }
    return out.toString();
}
Also used : PrintString(org.tomitribe.util.PrintString) ECField(java.security.spec.ECField) ECFieldFp(java.security.spec.ECFieldFp) ECFieldF2m(java.security.spec.ECFieldF2m) List(java.util.List) ArrayList(java.util.ArrayList) PrintString(org.tomitribe.util.PrintString)

Example 3 with PrintString

use of org.tomitribe.util.PrintString in project tomee-site-generator by apache.

the class ApisUsed method addApiList.

private static String addApiList(final String source, final String link, final String linkText) {
    final PrintString out = new PrintString();
    out.println("");
    out.println("== APIs Used");
    out.println("");
    out.printf("- link:%s[%s]%n", link, linkText);
    return source + out.toString();
}
Also used : PrintString(org.tomitribe.util.PrintString)

Example 4 with PrintString

use of org.tomitribe.util.PrintString in project churchkey by tomitribe.

the class KeyInput method readAuthMagic.

public String readAuthMagic() throws IOException {
    final PrintString string = new PrintString();
    int read = this.read();
    while (read != '\000') {
        if (read == -1)
            throw new EOFException();
        string.write(read);
        read = this.read();
    }
    return string.toString();
}
Also used : PrintString(org.tomitribe.util.PrintString) EOFException(java.io.EOFException)

Example 5 with PrintString

use of org.tomitribe.util.PrintString in project churchkey by tomitribe.

the class Pem method format.

public String format() {
    final PrintString out = new PrintString();
    out.println(header);
    for (final Map.Entry<String, String> entry : attributes.entrySet()) {
        out.printf("%s: \"%s\"%n", entry.getKey(), entry.getValue());
    }
    {
        // Write the data as base64 encoded
        final ByteArrayInputStream encoded = new ByteArrayInputStream(Base64.getEncoder().encode(data));
        try {
            final byte[] line = new byte[wrap];
            int length;
            while ((length = encoded.read(line)) != -1) {
                out.println(new String(line, 0, length));
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    out.println(footer);
    return out.toString();
}
Also used : PrintString(org.tomitribe.util.PrintString) ByteArrayInputStream(java.io.ByteArrayInputStream) UncheckedIOException(java.io.UncheckedIOException) PrintString(org.tomitribe.util.PrintString) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

PrintString (org.tomitribe.util.PrintString)7 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Pem (io.churchkey.util.Pem)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 EOFException (java.io.EOFException)1 File (java.io.File)1 UncheckedIOException (java.io.UncheckedIOException)1 ECField (java.security.spec.ECField)1 ECFieldF2m (java.security.spec.ECFieldF2m)1 ECFieldFp (java.security.spec.ECFieldFp)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 ExecutionException (java.util.concurrent.ExecutionException)1 JsonObject (javax.json.JsonObject)1 JsonReader (javax.json.JsonReader)1 JsonValue (javax.json.JsonValue)1 JsonGenerator (javax.json.stream.JsonGenerator)1