• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #pragma once
17 
18 #include <string>
19 #include <vector>
20 
21 #include "jsmn.h"
22 #include "ClearKeyTypes.h"
23 
24 namespace clearkeydrm {
25 
26 class JsonWebKey {
27   public:
28     JsonWebKey();
29     virtual ~JsonWebKey();
30 
31     bool extractKeysFromJsonWebKeySet(const std::string& jsonWebKeySet, KeyMap* keys);
32 
33   private:
34     std::vector<jsmntok_t> mJsmnTokens;
35     std::vector<std::string> mJsonObjects;
36     std::vector<std::string> mTokens;
37 
38     bool decodeBase64String(const std::string& encodedText, std::vector<uint8_t>* decodedText);
39     bool findKey(const std::string& jsonObject, std::string* keyId, std::string* encodedKey);
40     void findValue(const std::string& key, std::string* value);
41     bool isJsonWebKeySet(const std::string& jsonObject) const;
42     bool parseJsonObject(const std::string& jsonObject, std::vector<std::string>* tokens);
43     bool parseJsonWebKeySet(const std::string& jsonWebKeySet,
44                             std::vector<std::string>* jsonObjects);
45 
46     CLEARKEY_DISALLOW_COPY_AND_ASSIGN(JsonWebKey);
47 };
48 
49 }  // namespace clearkeydrm
50