@Override
    protected byte[] engineGetEncoded() throws IOException {
        long cbbRef = 0;
        long seqRef = 0;
        try {
            cbbRef = NativeCrypto.asn1_write_init();
            seqRef = NativeCrypto.asn1_write_sequence(cbbRef);
            writeHashAndMgfHash(seqRef, spec.getDigestAlgorithm(),
                    (MGF1ParameterSpec) spec.getMGFParameters());
            PSource.PSpecified pSource = (PSource.PSpecified) spec.getPSource();
            // Implementations are prohibited from writing the default value for any of the fields
            if (pSource.getValue().length != 0) {
                long pSourceRef = 0;
                long pSourceParamsRef = 0;
                try {
                    pSourceRef = NativeCrypto.asn1_write_tag(seqRef, 2);
                    pSourceParamsRef = writeAlgorithmIdentifier(pSourceRef, PSPECIFIED_OID);
                    NativeCrypto.asn1_write_octetstring(pSourceParamsRef, pSource.getValue());
                } finally {
                    NativeCrypto.asn1_write_flush(seqRef);
                    NativeCrypto.asn1_write_free(pSourceParamsRef);
                    NativeCrypto.asn1_write_free(pSourceRef);
                }
            }
            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 OAEP.  The only supported encoding format is ASN.1,
as specified in RFC 4055 section 4.1.
common/src/main/java/org/conscrypt/OAEPParameters.java