Crypto.h revision 1bd139a2a68690e80398b70b27ca59550fea0e65
1/*
2 * Copyright (C) 2012 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
17#ifndef CRYPTO_H_
18
19#define CRYPTO_H_
20
21#include <media/ICrypto.h>
22#include <utils/threads.h>
23
24namespace android {
25
26struct CryptoFactory;
27struct CryptoPlugin;
28
29struct Crypto : public BnCrypto {
30    Crypto();
31    virtual ~Crypto();
32
33    virtual status_t initCheck() const;
34
35    virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]) const;
36
37    virtual status_t createPlugin(
38            const uint8_t uuid[16], const void *data, size_t size);
39
40    virtual status_t destroyPlugin();
41
42    virtual bool requiresSecureDecoderComponent(
43            const char *mime) const;
44
45    virtual status_t decrypt(
46            bool secure,
47            const uint8_t key[16],
48            const uint8_t iv[16],
49            CryptoPlugin::Mode mode,
50            const void *srcPtr,
51            const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
52            void *dstPtr);
53
54private:
55    mutable Mutex mLock;
56
57    status_t mInitCheck;
58    void *mLibHandle;
59    CryptoFactory *mFactory;
60    CryptoPlugin *mPlugin;
61
62    status_t init();
63
64    DISALLOW_EVIL_CONSTRUCTORS(Crypto);
65};
66
67}  // namespace android
68
69#endif  // CRYPTO_H_
70