2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
21 #include <klay/exception.h>
22 #include <klay/filesystem.h>
25 #include "file-footer.h"
26 #include "key-manager/key-generator.h"
32 const std::string getFileName(const std::string &key)
34 BinaryData hash = KeyGenerator::SHA256(BinaryData(key.begin(), key.end()));
35 std::stringstream fileName;
37 fileName << "/opt/etc/.ode_";
38 fileName << std::hex << std::setfill('0') << std::setw(2);
39 for (unsigned int byte : hash) {
43 return fileName.str();
48 bool FileFooter::exist(const std::string &key)
50 std::string fileName(getFileName(key));
52 INFO(SINK, "Footer file : " + fileName);
54 runtime::File file(fileName);
59 const BinaryData FileFooter::read(const std::string &key)
61 std::string fileName(getFileName(key));
63 INFO(SINK, "Footer file : " + fileName);
65 runtime::File file(fileName);
66 BinaryData value(file.size());
69 file.read(value.data(), value.size());
74 void FileFooter::write(const std::string &key, const BinaryData &value)
76 std::string fileName(getFileName(key));
78 INFO(SINK, "Footer file : " + fileName);
80 runtime::File file(fileName);
82 file.create(S_IRUSR | S_IWUSR);
83 file.write(value.data(), value.size());
86 void FileFooter::clear(const std::string &key)
88 std::string fileName(getFileName(key));
90 INFO(SINK, "Footer file : " + fileName);
92 runtime::File file(fileName);