• 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 <errno.h>
19 #include <stdio.h>
20 #include <unistd.h>
21 
22 #include <set>
23 #include <string>
24 #include <vector>
25 
26 #include "ClearKeyTypes.h"
27 #include "MemoryFileSystem.h"
28 
29 namespace clearkeydrm {
30 class OfflineFile;
31 class DeviceFiles {
32   public:
33     typedef enum {
34         kLicenseStateUnknown,
35         kLicenseStateActive,
36         kLicenseStateReleasing,
37     } LicenseState;
38 
DeviceFiles()39     DeviceFiles(){};
~DeviceFiles()40     virtual ~DeviceFiles(){};
41 
42     virtual bool StoreLicense(const std::string& keySetId, LicenseState state,
43                               const std::string& keyResponse);
44 
45     virtual bool RetrieveLicense(const std::string& key_set_id, LicenseState* state,
46                                  std::string* offlineLicense);
47 
48     virtual bool LicenseExists(const std::string& keySetId);
49 
50     virtual std::vector<std::string> ListLicenses() const;
51 
52     virtual bool DeleteLicense(const std::string& keySetId);
53 
54     virtual bool DeleteAllLicenses();
55 
56   private:
57     bool FileExists(const std::string& path) const;
58     ssize_t GetFileSize(const std::string& fileName) const;
59     bool RemoveFile(const std::string& fileName);
60 
61     bool RetrieveHashedFile(
62             const std::string& fileName,
63             OfflineFile* deSerializedFile);
64     bool StoreFileRaw(const std::string& fileName, const std::string& serializedFile);
65     bool StoreFileWithHash(const std::string& fileName, const std::string& serializedFile);
66 
67     MemoryFileSystem mFileHandle;
68 
69     CLEARKEY_DISALLOW_COPY_AND_ASSIGN(DeviceFiles);
70 };
71 
72 }  // namespace clearkeydrm
73