1cc290419Sopenharmony_ci#!/usr/bin/env python3
2cc290419Sopenharmony_ci# -*- coding: utf-8 -*-
3cc290419Sopenharmony_ci# Copyright (C) 2024 Huawei Device Co., Ltd.
4cc290419Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
5cc290419Sopenharmony_ci# you may not use this file except in compliance with the License.
6cc290419Sopenharmony_ci# You may obtain a copy of the License at
7cc290419Sopenharmony_ci#
8cc290419Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
9cc290419Sopenharmony_ci#
10cc290419Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
11cc290419Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
12cc290419Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cc290419Sopenharmony_ci# See the License for the specific language governing permissions and
14cc290419Sopenharmony_ci# limitations under the License.
15cc290419Sopenharmony_ciimport hashlib
16cc290419Sopenharmony_ciimport os.path
17cc290419Sopenharmony_ci
18cc290419Sopenharmony_ciif __name__ == '__main__':
19cc290419Sopenharmony_ci    home_dir = os.path.expanduser("~")
20cc290419Sopenharmony_ci    hdckey_path = os.path.join(home_dir, ".harmony", "hdckey.pub")
21cc290419Sopenharmony_ci
22cc290419Sopenharmony_ci    if os.path.exists(hdckey_path):
23cc290419Sopenharmony_ci        with open(hdckey_path, "r") as f:
24cc290419Sopenharmony_ci            hdckey_content = f.read()
25cc290419Sopenharmony_ci            sha256 = hashlib.sha256()
26cc290419Sopenharmony_ci            sha256.update(hdckey_content.encode())
27cc290419Sopenharmony_ci            result = sha256.hexdigest()
28cc290419Sopenharmony_ci            upper = result.upper()
29cc290419Sopenharmony_ci            final = ':'.join([upper[i : i + 2] for i in range(0, len(upper), 2)])
30cc290419Sopenharmony_ci            print(final)
31cc290419Sopenharmony_ci    else:
32cc290419Sopenharmony_ci        print("hdckey.pub 文件不存在")