1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.weaver;
18
19public interface Slots extends javacard.framework.Shareable {
20    /** @return The number of slots available. */
21    short getNumSlots();
22
23    /**
24     * Write the key and value to the identified slot.
25     *
26     * @param slotId ID of the slot to write to.
27     * @param key Buffer containing the key.
28     * @param keyOffset Offset of the key in the buffer.
29     * @param value Buffer containing the value.
30     * @param valueOffset Offset of the value in the buffer.
31     */
32    void write(short slotId, byte[] key, short keyOffset, byte[] value, short valueOffset);
33
34    /**
35     * Read the value from the identified slot.
36     *
37     * This is only successful if the key matches that stored in the slot.
38     *
39     * @param slotId ID of the slot to write to.
40     * @param key Buffer containing the key.
41     * @param keyOffset Offset of the key in the buffer.
42     * @param value Buffer to receive the value.
43     * @param valueOffset Offset into the buffer to write the value.
44     * @return Status byte indicating the success or otherwise of the read.
45     */
46    byte read(short slotId, byte[] key, short keyOffset, byte[] value, short valueOffset);
47
48    /**
49     * Set the value of the identified slot to all zeros whilst leaving the key untouched.
50     *
51     * This is used to destroy the secret stored in the slot but retain the ability to authenticate
52     * by comparing a challenege with the slot's key.
53     *
54     * @param slotId ID of the slot of which to erase the value.
55     */
56    void eraseValue(short slotId);
57
58    /** Erases the key and value of all slots. */
59    void eraseAll();
60}
61