Projects >> platform_frameworks_base >>b9b5d86b0e2a7e32259f2606024745439ebb43e1

Chunk
Conflicting content
        return toUint64(((KeymasterLongArgument) arg).value);
    }

<<<<<<< HEAD
    /**
     * Adds the provided boolean tag. Boolean tags are considered to be set to {@code true} if
     * present and {@code false} if absent.
     *
     * @throws IllegalArgumentException if {@code tag} is not a boolean tag.
     */
    public void addBoolean(int tag) {
        if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_BOOL) {
            throw new IllegalArgumentException("Not a boolean tag: " + tag);
        }
        mArguments.add(new KeymasterBooleanArgument(tag));
    }

    /**
     * Returns {@code true} if the provided boolean tag is present, {@code false} if absent.
     *
     * @throws IllegalArgumentException if {@code tag} is not a boolean tag.
     */
    public boolean getBoolean(int tag) {
        if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_BOOL) {
            throw new IllegalArgumentException("Not a boolean tag: " + tag);
=======
    public int getInt(int tag, int defaultValue) {
        switch (KeymasterDefs.getTagType(tag)) {
            case KeymasterDefs.KM_ENUM:
            case KeymasterDefs.KM_UINT:
                break; // Accepted types
            case KeymasterDefs.KM_UINT_REP:
            case KeymasterDefs.KM_ENUM_REP:
                throw new IllegalArgumentException("Repeatable tags must use getInts: " + tag);
            default:
                throw new IllegalArgumentException("Tag is not an int type: " + tag);
>>>>>>> b15e1ff5081b680f4848a07fdbe6009c9a0fbde0
        }
        KeymasterArgument arg = getArgumentByTag(tag);
        if (arg == null) {
Solution content
        return toUint64(((KeymasterLongArgument) arg).value);
    }

    /**
     * Adds the provided boolean tag. Boolean tags are considered to be set to {@code true} if
     * present and {@code false} if absent.
     *
     * @throws IllegalArgumentException if {@code tag} is not a boolean tag.
     */
    public void addBoolean(int tag) {
        if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_BOOL) {
            throw new IllegalArgumentException("Not a boolean tag: " + tag);
        }
        mArguments.add(new KeymasterBooleanArgument(tag));
    }

    /**
     * Returns {@code true} if the provided boolean tag is present, {@code false} if absent.
     *
     * @throws IllegalArgumentException if {@code tag} is not a boolean tag.
     */
    public boolean getBoolean(int tag) {
        if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_BOOL) {
            throw new IllegalArgumentException("Not a boolean tag: " + tag);
        }
        KeymasterArgument arg = getArgumentByTag(tag);
        if (arg == null) {
File
KeymasterArguments.java
Developer's decision
Version 1
Kind of conflict
Break statement
Case statement
Comment
If statement
Method declaration
Method signature
Switch statement
Throw statement
Chunk
Conflicting content
        return true;
    }

<<<<<<< HEAD
    /**
     * Adds a bytes tag with the provided value.
     *
     * @throws IllegalArgumentException if {@code tag} is not a bytes tag.
     */
    public void addBytes(int tag, byte[] value) {
        if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_BYTES) {
            throw new IllegalArgumentException("Not a bytes tag: " + tag);
        }
        if (value == null) {
            throw new NullPointerException("value == nulll");
        }
        mArguments.add(new KeymasterBlobArgument(tag, value));
    }

    /**
     * Returns the value of the specified bytes tag or {@code defaultValue} if the tag is not
     * present.
     *
     * @throws IllegalArgumentException if {@code tag} is not a bytes tag.
     */
    public byte[] getBytes(int tag, byte[] defaultValue) {
        if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_BYTES) {
            throw new IllegalArgumentException("Not a bytes tag: " + tag);
=======
    public long getLong(int tag, long defaultValue) {
        switch (KeymasterDefs.getTagType(tag)) {
            case KeymasterDefs.KM_ULONG:
                break; // Accepted type
            case KeymasterDefs.KM_ULONG_REP:
                throw new IllegalArgumentException("Repeatable tags must use getLongs: " + tag);
            default:
                throw new IllegalArgumentException("Tag is not a long type: " + tag);
>>>>>>> b15e1ff5081b680f4848a07fdbe6009c9a0fbde0
        }
        KeymasterArgument arg = getArgumentByTag(tag);
        if (arg == null) {
Solution content
        return true;
    }

    /**
     * Adds a bytes tag with the provided value.
     *
     * @throws IllegalArgumentException if {@code tag} is not a bytes tag.
     */
    public void addBytes(int tag, byte[] value) {
        if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_BYTES) {
            throw new IllegalArgumentException("Not a bytes tag: " + tag);
        }
        if (value == null) {
            throw new NullPointerException("value == nulll");
        }
        mArguments.add(new KeymasterBlobArgument(tag, value));
    }

    /**
     * Returns the value of the specified bytes tag or {@code defaultValue} if the tag is not
     * present.
     *
     * @throws IllegalArgumentException if {@code tag} is not a bytes tag.
     */
    public byte[] getBytes(int tag, byte[] defaultValue) {
        if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_BYTES) {
            throw new IllegalArgumentException("Not a bytes tag: " + tag);
        }
        KeymasterArgument arg = getArgumentByTag(tag);
        if (arg == null) {
File
KeymasterArguments.java
Developer's decision
Version 1
Kind of conflict
Break statement
Case statement
Comment
If statement
Method declaration
Method signature
Switch statement
Throw statement
Chunk
Conflicting content
        return result;
    }

<<<<<<< HEAD
    private KeymasterArgument getArgumentByTag(int tag) {
=======
    public List getInts(int tag) {
        switch (KeymasterDefs.getTagType(tag)) {
            case KeymasterDefs.KM_UINT_REP:
            case KeymasterDefs.KM_ENUM_REP:
                break; // Allowed types.
            default:
                throw new IllegalArgumentException("Tag is not a repeating type: " + tag);
        }
        List values = new ArrayList();
>>>>>>> b15e1ff5081b680f4848a07fdbe6009c9a0fbde0
        for (KeymasterArgument arg : mArguments) {
            if (arg.tag == tag) {
                return arg;
Solution content
        return result;
    }

    private KeymasterArgument getArgumentByTag(int tag) {
        for (KeymasterArgument arg : mArguments) {
            if (arg.tag == tag) {
                return arg;
File
KeymasterArguments.java
Developer's decision
Version 1
Kind of conflict
Method invocation
Method signature
Switch statement
Variable
Chunk
Conflicting content
        return null;
    }

<<<<<<< HEAD
    public boolean containsTag(int tag) {
        return getArgumentByTag(tag) != null;
=======
    public List getLongs(int tag) {
        if (KeymasterDefs.getTagType(tag) != KeymasterDefs.KM_ULONG_REP) {
            throw new IllegalArgumentException("Tag is not a repeating long: " + tag);
        }
        List values = new ArrayList();
        for (KeymasterArgument arg : mArguments) {
            if (arg.tag == tag) {
                values.add(((KeymasterLongArgument) arg).value);
            }
        }
        return values;
>>>>>>> b15e1ff5081b680f4848a07fdbe6009c9a0fbde0
    }

    public int size() {
Solution content
        return null;
    }

    public boolean containsTag(int tag) {
        return getArgumentByTag(tag) != null;
    }

    public int size() {
File
KeymasterArguments.java
Developer's decision
Version 1
Kind of conflict
For statement
If statement
Method invocation
Method signature
Return statement
Variable
Chunk
Conflicting content
    }
        // TODO: Verify we have an RSA public key that's well formed.
    }

<<<<<<< HEAD
    public void testAesGcmEncryptSuccess() throws Exception {
        String name = "test";
        KeymasterArguments args = new KeymasterArguments();
        args.addEnum(KeymasterDefs.KM_TAG_PURPOSE, KeymasterDefs.KM_PURPOSE_ENCRYPT);
        args.addEnum(KeymasterDefs.KM_TAG_PURPOSE, KeymasterDefs.KM_PURPOSE_DECRYPT);
        args.addEnum(KeymasterDefs.KM_TAG_ALGORITHM, KeymasterDefs.KM_ALGORITHM_AES);
        args.addEnum(KeymasterDefs.KM_TAG_PADDING, KeymasterDefs.KM_PAD_NONE);
        args.addUnsignedInt(KeymasterDefs.KM_TAG_KEY_SIZE, 256);
        args.addEnum(KeymasterDefs.KM_TAG_BLOCK_MODE, KeymasterDefs.KM_MODE_GCM);
        args.addBoolean(KeymasterDefs.KM_TAG_NO_AUTH_REQUIRED);

        KeyCharacteristics outCharacteristics = new KeyCharacteristics();
        int rc = mKeyStore.generateKey(name, args, null, 0, outCharacteristics);
        assertEquals("Generate should succeed", KeyStore.NO_ERROR, rc);

        args = new KeymasterArguments();
        args.addEnum(KeymasterDefs.KM_TAG_ALGORITHM, KeymasterDefs.KM_ALGORITHM_AES);
        args.addEnum(KeymasterDefs.KM_TAG_BLOCK_MODE, KeymasterDefs.KM_MODE_GCM);
        args.addEnum(KeymasterDefs.KM_TAG_PADDING, KeymasterDefs.KM_PAD_NONE);
        args.addUnsignedInt(KeymasterDefs.KM_TAG_MAC_LENGTH, 128);
        OperationResult result = mKeyStore.begin(name, KeymasterDefs.KM_PURPOSE_ENCRYPT,
                true, args, null);
        IBinder token = result.token;
        assertEquals("Begin should succeed", KeyStore.NO_ERROR, result.resultCode);
        result = mKeyStore.update(token, null, new byte[] {0x01, 0x02, 0x03, 0x04});
        assertEquals("Update should succeed", KeyStore.NO_ERROR, result.resultCode);
        assertEquals("Finish should succeed", KeyStore.NO_ERROR,
                mKeyStore.finish(token, null, null).resultCode);
        // TODO: Assert that an AEAD tag was returned by finish

=======
>>>>>>> b15e1ff5081b680f4848a07fdbe6009c9a0fbde0
    public void testBadToken() throws Exception {
        IBinder token = new Binder();
        OperationResult result = mKeyStore.update(token, null, new byte[] {0x01});
Solution content
        // TODO: Verify we have an RSA public key that's well formed.
    }

    public void testAesGcmEncryptSuccess() throws Exception {
        String name = "test";
        KeymasterArguments args = new KeymasterArguments();
        args.addEnum(KeymasterDefs.KM_TAG_PURPOSE, KeymasterDefs.KM_PURPOSE_ENCRYPT);
        args.addEnum(KeymasterDefs.KM_TAG_PURPOSE, KeymasterDefs.KM_PURPOSE_DECRYPT);
        args.addEnum(KeymasterDefs.KM_TAG_ALGORITHM, KeymasterDefs.KM_ALGORITHM_AES);
        args.addEnum(KeymasterDefs.KM_TAG_PADDING, KeymasterDefs.KM_PAD_NONE);
        args.addUnsignedInt(KeymasterDefs.KM_TAG_KEY_SIZE, 256);
        args.addEnum(KeymasterDefs.KM_TAG_BLOCK_MODE, KeymasterDefs.KM_MODE_GCM);
        args.addBoolean(KeymasterDefs.KM_TAG_NO_AUTH_REQUIRED);

        KeyCharacteristics outCharacteristics = new KeyCharacteristics();
        int rc = mKeyStore.generateKey(name, args, null, 0, outCharacteristics);
        assertEquals("Generate should succeed", KeyStore.NO_ERROR, rc);

        args = new KeymasterArguments();
        args.addEnum(KeymasterDefs.KM_TAG_ALGORITHM, KeymasterDefs.KM_ALGORITHM_AES);
        args.addEnum(KeymasterDefs.KM_TAG_BLOCK_MODE, KeymasterDefs.KM_MODE_GCM);
        args.addEnum(KeymasterDefs.KM_TAG_PADDING, KeymasterDefs.KM_PAD_NONE);
        args.addUnsignedInt(KeymasterDefs.KM_TAG_MAC_LENGTH, 128);
        OperationResult result = mKeyStore.begin(name, KeymasterDefs.KM_PURPOSE_ENCRYPT,
                true, args, null);
        IBinder token = result.token;
        assertEquals("Begin should succeed", KeyStore.NO_ERROR, result.resultCode);
        result = mKeyStore.update(token, null, new byte[] {0x01, 0x02, 0x03, 0x04});
        assertEquals("Update should succeed", KeyStore.NO_ERROR, result.resultCode);
        assertEquals("Finish should succeed", KeyStore.NO_ERROR,
                mKeyStore.finish(token, null, null).resultCode);
        // TODO: Assert that an AEAD tag was returned by finish
    }

    public void testBadToken() throws Exception {
        IBinder token = new Binder();
        OperationResult result = mKeyStore.update(token, null, new byte[] {0x01});
File
KeyStoreTest.java
Developer's decision
Version 1
Kind of conflict
Method declaration