Home / Function/ String() — netty Function Reference

String() — netty Function Reference

Architecture documentation for the String() function in CertificateBuilder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  77b332f9_dcd9_f4b6_a769_4e6222101897["String()"]
  4aeffc80_93f6_788a_f8c6_901cee3b8997["CertificateBuilder"]
  77b332f9_dcd9_f4b6_a769_4e6222101897 -->|defined in| 4aeffc80_93f6_788a_f8c6_901cee3b8997
  style 77b332f9_dcd9_f4b6_a769_4e6222101897 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

pkitesting/src/main/java/io/netty/pkitesting/CertificateBuilder.java lines 769–822

    private static String preferredSignatureAlgorithm(PublicKey key) {
        if (key instanceof RSAPublicKey) {
            RSAPublicKey rsa = (RSAPublicKey) key;
            if (rsa.getModulus().bitLength() < 4096) {
                return "SHA256withRSA";
            }
            return "SHA384withRSA";
        }
        if (key instanceof ECPublicKey) {
            ECPublicKey ec = (ECPublicKey) key;
            int size = ec.getW().getAffineX().bitLength();
            // Note: the coords are not guaranteed to use up all available bits, hence less-than-or-equal checks.
            if (size <= 256) {
                return "SHA256withECDSA";
            }
            if (size <= 384) {
                return "SHA384withECDSA";
            }
            return "SHA512withECDSA";
        }
        if (key instanceof DSAPublicKey) {
            throw new IllegalArgumentException("DSA keys are not supported because they are obsolete");
        }
        String keyAlgorithm = key.getAlgorithm();
        if ("Ed25519".equals(keyAlgorithm) || "1.3.101.112".equals(keyAlgorithm)) {
            return "Ed25519";
        }
        if ("Ed448".equals(keyAlgorithm) || "1.3.101.113".equals(keyAlgorithm)) {
            return "Ed448";
        }
        if ("EdDSA".equals(keyAlgorithm)) {
            byte[] encoded = key.getEncoded();
            if (encoded.length <= 44) {
                return "Ed25519";
            }
            if (encoded.length <= 69) {
                return "Ed448";
            }
        }
        if ("ML-DSA".equals(keyAlgorithm)) {
            try {
                Method getParams = Class.forName("java.security.AsymmetricKey").getMethod("getParams");
                Object params = getParams.invoke(key);
                Method getName = params.getClass().getMethod("getName");
                return (String) getName.invoke(params);
            } catch (Exception e) {
                throw new IllegalArgumentException("Cannot get algorithm name for ML-DSA key", e);
            }
        }
        if ("ML-KEM".equals(keyAlgorithm)) {
            throw new IllegalArgumentException("ML-KEM keys cannot be used for signing");
        }
        throw new IllegalArgumentException("Don't know what signature algorithm is best for " + key);
    }

Domain

Subdomains

Frequently Asked Questions

What does String() do?
String() is a function in the netty codebase, defined in pkitesting/src/main/java/io/netty/pkitesting/CertificateBuilder.java.
Where is String() defined?
String() is defined in pkitesting/src/main/java/io/netty/pkitesting/CertificateBuilder.java at line 769.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free