-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to Python 3, code reformat make it more readable and pythonic. #5
base: master
Are you sure you want to change the base?
Conversation
@crb912 sorry this has sat for so long, I'll take a look real quick. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR - looks like there's some changes to make it even more Pythonic, as well as some grammatical fixes.
""" | ||
unpack all rsa data. | ||
""" | ||
def get_value(x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_value
is solely used for L79-L84, could these possibly be squashed to something that returns a tuple of the key values from the file contents?
data = base64.b64encode(raw) | ||
|
||
# chop data up into lines of certain width | ||
width = 64 | ||
chopped = [data[i:i + width] for i in xrange(0, len(data), width)] | ||
chopped = [data[i:i + width].decode('utf-8') for i in range(0, len(data), width)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to assume that this content will be UTF-8 encoded? Wouldn't it matter on the OS's preferred encoding on the server?
for magic in magic_headers: | ||
offset = self.file_content.find(magic.encode(encoding='ascii')) | ||
if offset: | ||
print("Success find key type! key type:{}, key start offset:0x" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammatical improvements needed here.
print("Success find key type! key type:{}, key start offset:0x" | |
print("Successfully found key type {} at offset:0x" |
return v | ||
|
||
|
||
t = SshKeyParse() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L141-L145 should be moved to a main()
method with an if __name__ == __main__:
or similar.
|
||
def read(self, fp): | ||
""" | ||
Reads a file and stories it in self.file_content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor typo.
Reads a file and stories it in self.file_content | |
Reads a file and stores it in self.file_content |
return found_keys | ||
print("Not find any optional keys match any one in:{}".format( | ||
magic_headers)) | ||
print("Program exit!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't guaranteed to cause the program to exit - see my comments near L141 about this.
print("Program exit!") |
for key_type in valid_key: | ||
if "ssh-rsa" == key_type: | ||
self.get_rsa_key(output_fp) | ||
print("\nhave output {} key, File Path:{}".format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The \n
is at the beginning of the print line, which can mess with shells - also, what's the purpose of this?
Co-Authored-By: crb912 <[email protected]>
Co-Authored-By: crb912 <[email protected]>
No description provided.