public DigestCalculator get()

in jsign-core/src/main/java/net/jsign/asn1/authenticode/AuthenticodeDigestCalculatorProvider.java [41:72]


    public DigestCalculator get(final AlgorithmIdentifier digestAlgorithmIdentifier) throws OperatorCreationException {
        final DigestCalculator delegate = new JcaDigestCalculatorProviderBuilder().build().get(digestAlgorithmIdentifier);

        return new DigestCalculator() {
            private final ByteArrayOutputStream out = new ByteArrayOutputStream();

            @Override
            public AlgorithmIdentifier getAlgorithmIdentifier() {
                return digestAlgorithmIdentifier;
            }

            @Override
            public OutputStream getOutputStream() {
                return out;
            }

            @Override
            public byte[] getDigest() {
                try {
                    ASN1InputStream in = new ASN1InputStream(out.toByteArray());
                    ASN1Sequence sequence = (ASN1Sequence) in.readObject();
                    for (ASN1Encodable element : sequence) {
                        delegate.getOutputStream().write(element.toASN1Primitive().getEncoded());
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }

                return delegate.getDigest();
            }
        };
    }