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 ssize_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            AString *errorDetailMsg);
54
55private:
56    mutable Mutex mLock;
57
58    status_t mInitCheck;
59    void *mLibHandle;
60    CryptoFactory *mFactory;
61    CryptoPlugin *mPlugin;
62
63    status_t init();
64
65    DISALLOW_EVIL_CONSTRUCTORS(Crypto);
66};
67
68}  // namespace android
69
70#endif  // CRYPTO_H_
71