// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary // source code may only be used and distributed under the Widevine Master // License Agreement. #ifndef ECM_PARSER_H #define ECM_PARSER_H #include #include #include "cas_types.h" namespace wvcas { enum class KeySlotId { kEvenKeySlot, kOddKeySlot }; struct EcmKeyData; // EcmParser allows random access to the fields of an ECM. // The only validation performed is to ensure that the ecm // passed in is large enough to hold a single key entry. class EcmParser { protected: EcmParser() {} public: virtual ~EcmParser() {} // The EcmParser factory method. // Validates the ecm. If validations is successful returns true and constructs // an EcmParser in |parser| using |ecm|. static bool create(const CasEcm& ecm, std::unique_ptr* parser); // Accessor methods. virtual uint8_t version() const; virtual uint8_t sequence_count() const; virtual CryptoMode crypto_mode() const; virtual bool rotation_enabled() const; virtual size_t content_iv_size() const; virtual uint8_t age_restriction() const; virtual const std::vector entitlement_key_id(KeySlotId id) const; virtual const std::vector content_key_id(KeySlotId id) const; virtual const std::vector wrapped_key_data(KeySlotId id) const; virtual const std::vector wrapped_key_iv(KeySlotId id) const; virtual const std::vector content_iv(KeySlotId id) const; EcmParser(const EcmParser&) = delete; EcmParser& operator=(const EcmParser&) = delete; private: // Constructs an EcmParser using |ecm|. explicit EcmParser(const CasEcm& ecm); size_t key_data_size() const; // Returns false if the ecm used to construct the object is not a valid size. // TODO(jfore): Add validation using the version field. bool is_valid_size() const; const EcmKeyData* key_slot_data(KeySlotId id) const; CasEcm ecm_; }; } // namespace wvcas #endif // ECM_PARSER_H