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.server.locksettings.recoverablekeystore;
18
19import android.security.keystore.AndroidKeyStoreSecretKey;
20
21/**
22 * Used to unwrap recoverable keys before syncing them with remote storage.
23 *
24 * <p>This is a private key stored in AndroidKeyStore. Has an associated generation ID, which is
25 * stored with wrapped keys, allowing us to ensure the wrapped key has the same version as the
26 * platform key.
27 *
28 * @hide
29 */
30public class PlatformDecryptionKey {
31
32    private final int mGenerationId;
33    private final AndroidKeyStoreSecretKey mKey;
34
35    /**
36     * A new instance.
37     *
38     * @param generationId The generation ID of the platform key.
39     * @param key The key handle in AndroidKeyStore.
40     *
41     * @hide
42     */
43    public PlatformDecryptionKey(int generationId, AndroidKeyStoreSecretKey key) {
44        mGenerationId = generationId;
45        mKey = key;
46    }
47
48    /**
49     * Returns the generation ID.
50     *
51     * @hide
52     */
53    public int getGenerationId() {
54        return mGenerationId;
55    }
56
57    /**
58     * Returns the actual key, which can be used to decrypt.
59     *
60     * @hide
61     */
62    public AndroidKeyStoreSecretKey getKey() {
63        return mKey;
64    }
65}
66