Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e305f45f authored by Alex Klyubin's avatar Alex Klyubin
Browse files

Offer an ApkSignerEngine implementation.

This adds an implementation of ApkSignerEngine to the apksigner-core
library.

Bug: 27461702
Change-Id: I5f977b98555ca507a0dfcd3e92eecb9758aa8370
parent afd3d552
Loading
Loading
Loading
Loading
+870 −0

File added.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -24,11 +24,11 @@ import java.security.MessageDigest;
 * Data sink which feeds all received data into the associated {@link MessageDigest} instances. Each
 * {@code MessageDigest} instance receives the same data.
 */
class MessageDigestSink implements DataSink {
public class MessageDigestSink implements DataSink {

    private final MessageDigest[] mMessageDigests;

    MessageDigestSink(MessageDigest[] digests) {
    public MessageDigestSink(MessageDigest[] digests) {
        mMessageDigests = digests;
    }

+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.apksigner.core.internal.util;

import com.android.apksigner.core.util.DataSink;

import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;

/**
 * Data sink which stores all input data into an internal {@link ByteArrayOutputStream}, thus
 * accepting an arbitrary amount of data.
 */
public class ByteArrayOutputStreamSink implements DataSink {

    private final ByteArrayOutputStream mBuf = new ByteArrayOutputStream();

    @Override
    public void consume(byte[] buf, int offset, int length) {
        mBuf.write(buf, offset, length);
    }

    @Override
    public void consume(ByteBuffer buf) {
        if (!buf.hasRemaining()) {
            return;
        }

        if (buf.hasArray()) {
            mBuf.write(
                    buf.array(),
                    buf.arrayOffset() + buf.position(),
                    buf.remaining());
            buf.position(buf.limit());
        } else {
            byte[] tmp = new byte[buf.remaining()];
            buf.get(tmp);
            mBuf.write(tmp, 0, tmp.length);
        }
    }

    /**
     * Returns the data received so far.
     */
    public byte[] getData() {
        return mBuf.toByteArray();
    }
}