@Override
    protected byte[] engineGetEncoded() throws IOException {
        long cbbRef = 0;
        long seqRef = 0;
        try {
            cbbRef = NativeCrypto.asn1_write_init();
            seqRef = NativeCrypto.asn1_write_sequence(cbbRef);
            OAEPParameters.writeHashAndMgfHash(seqRef, spec.getDigestAlgorithm(),
                    (MGF1ParameterSpec) spec.getMGFParameters());
            // Implementations are prohibited from writing the default value for any of the fields
            if (spec.getSaltLength() != 20) {
                long tagRef = 0;
                try {
                    tagRef = NativeCrypto.asn1_write_tag(seqRef, 2);
                    NativeCrypto.asn1_write_uint64(tagRef, spec.getSaltLength());
                } finally {
                    NativeCrypto.asn1_write_flush(seqRef);
                    NativeCrypto.asn1_write_free(tagRef);
                }
            }
            // 1 is the only legal value for trailerField and the default, so ignore it
            return NativeCrypto.asn1_write_finish(cbbRef);
        } catch (IOException e) {
            NativeCrypto.asn1_write_cleanup(cbbRef);
            throw e;
        } finally {
            NativeCrypto.asn1_write_free(seqRef);
            NativeCrypto.asn1_write_free(cbbRef);
        }
    }
AlgorithmParameters implementation for PSS.  The only supported encoding format is ASN.1
(with X.509 accepted as an alias), as specified in RFC 4055 section 3.1.
common/src/main/java/org/conscrypt/PSSParameters.java