commit d1edce71135cc6d98c0a4b5729774542b676e769 Author: sophgo-forum-service <forum_service@sophgo.com> Date: Fri Mar 15 16:07:33 2024 +0800 [fix] recommend using ssh method to clone repo. [fix] fix sensor driver repo branch name.
30 lines
618 B
Python
Executable File
30 lines
618 B
Python
Executable File
#!/usr/bin/env python3
|
|
# PYTHON_ARGCOMPLETE_OK
|
|
|
|
import sys
|
|
import hashlib
|
|
import rsa
|
|
|
|
|
|
def main():
|
|
with open(sys.argv[1], "rb") as ifp:
|
|
din = ifp.read()
|
|
|
|
try:
|
|
priv = rsa.PrivateKey.load_pkcs1(din)
|
|
except ValueError:
|
|
priv = rsa.PrivateKey.load_pkcs1(din, format="DER")
|
|
x = rsa.common.byte_size(priv.n)
|
|
n = priv.n.to_bytes(x, byteorder="big")
|
|
digest = hashlib.sha256(n).digest()
|
|
|
|
if sys.argv[2] == "-":
|
|
sys.stdout.buffer.write(digest)
|
|
else:
|
|
with open(sys.argv[2], "wb") as ofp:
|
|
ofp.write(digest)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|