JsonWebKey.h revision 7bdf28d2b83e527f474e96b0984d6a3f5eb457f7
1/* 2 * Copyright (C) 2014 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 <media/stagefright/foundation/ABase.h> 20#include <utils/KeyedVector.h> 21#include <utils/String8.h> 22#include <utils/StrongPointer.h> 23 24#include "jsmn.h" 25#include "Utils.h" 26#include "ClearKeyTypes.h" 27 28namespace clearkeydrm { 29 30using android::KeyedVector; 31using android::sp; 32using android::String8; 33using android::Vector; 34 35class JsonWebKey { 36 public: 37 JsonWebKey(); 38 virtual ~JsonWebKey(); 39 40 bool extractKeysFromJsonWebKeySet(const String8& jsonWebKeySet, 41 KeyMap* keys); 42 43 private: 44 Vector<jsmntok_t> mJsmnTokens; 45 Vector<String8> mJsonObjects; 46 Vector<String8> mTokens; 47 48 bool decodeBase64String(const String8& encodedText, 49 Vector<uint8_t>* decodedText); 50 bool findKey(const String8& jsonObject, String8* keyId, 51 String8* encodedKey); 52 void findValue(const String8 &key, String8* value); 53 bool isJsonWebKeySet(const String8& jsonObject) const; 54 bool parseJsonObject(const String8& jsonObject, Vector<String8>* tokens); 55 bool parseJsonWebKeySet(const String8& jsonWebKeySet, Vector<String8>* jsonObjects); 56 57 DISALLOW_EVIL_CONSTRUCTORS(JsonWebKey); 58}; 59 60} // namespace clearkeydrm 61 62#endif // CLEARKEY_JSON_WEB_KEY_H_ 63