Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2018 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 #ifndef CLEARKEY_JSON_WEB_KEY_H_
     17 #define CLEARKEY_JSON_WEB_KEY_H_
     18 
     19 #include "jsmn.h"
     20 #include "Utils.h"
     21 #include "ClearKeyTypes.h"
     22 
     23 namespace android {
     24 namespace hardware {
     25 namespace drm {
     26 namespace V1_1 {
     27 namespace clearkey {
     28 
     29 class JsonWebKey {
     30  public:
     31     JsonWebKey();
     32     virtual ~JsonWebKey();
     33 
     34     bool extractKeysFromJsonWebKeySet(const std::string& jsonWebKeySet,
     35             KeyMap* keys);
     36 
     37  private:
     38     std::vector<jsmntok_t> mJsmnTokens;
     39     std::vector<std::string> mJsonObjects;
     40     std::vector<std::string> mTokens;
     41 
     42     bool decodeBase64String(const std::string& encodedText,
     43             std::vector<uint8_t>* decodedText);
     44     bool findKey(const std::string& jsonObject, std::string* keyId,
     45             std::string* encodedKey);
     46     void findValue(const std::string &key, std::string* value);
     47     bool isJsonWebKeySet(const std::string& jsonObject) const;
     48     bool parseJsonObject(const std::string& jsonObject,
     49             std::vector<std::string>* tokens);
     50     bool parseJsonWebKeySet(const std::string& jsonWebKeySet,
     51             std::vector<std::string>* jsonObjects);
     52 
     53     CLEARKEY_DISALLOW_COPY_AND_ASSIGN(JsonWebKey);
     54 };
     55 
     56 } // namespace clearkey
     57 } // namespace V1_1
     58 } // namespace drm
     59 } // namespace hardware
     60 } // namespace android
     61 
     62 #endif  // CLEARKEY_JSON_WEB_KEY_H_
     63