Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-sshkey
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
35336d9e
authored
Jul 02, 2014
by
Scott Duckworth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract key parts in constructor
parent
6ac5412d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
13 deletions
+12
-13
django_sshkey/util.py
+12
-13
No files found.
django_sshkey/util.py
View file @
35336d9e
...
@@ -74,9 +74,14 @@ class PublicKey(object):
...
@@ -74,9 +74,14 @@ class PublicKey(object):
def
__init__
(
self
,
b64key
,
comment
=
None
):
def
__init__
(
self
,
b64key
,
comment
=
None
):
self
.
b64key
=
b64key
self
.
b64key
=
b64key
self
.
comment
=
comment
self
.
comment
=
comment
self
.
keydata
=
base64
.
b64decode
(
b64key
.
encode
(
'ascii'
))
keydata
=
base64
.
b64decode
(
b64key
.
encode
(
'ascii'
))
n
=
struct
.
unpack
(
'>I'
,
self
.
keydata
[:
4
])
self
.
keydata
=
keydata
self
.
algorithm
=
self
.
keydata
[
4
:
4
+
n
[
0
]]
self
.
parts
=
[]
while
keydata
:
dlen
=
struct
.
unpack
(
'>I'
,
keydata
[:
4
])[
0
]
data
,
keydata
=
keydata
[
4
:
4
+
dlen
],
keydata
[
4
+
dlen
:]
self
.
parts
.
append
(
data
)
self
.
algorithm
=
self
.
parts
[
0
]
def
fingerprint
(
self
):
def
fingerprint
(
self
):
import
hashlib
import
hashlib
...
@@ -99,18 +104,12 @@ class PublicKey(object):
...
@@ -99,18 +104,12 @@ class PublicKey(object):
return
out
return
out
def
format_pem
(
self
):
def
format_pem
(
self
):
if
self
.
algorithm
!=
'ssh-rsa'
:
if
self
.
algorithm
!=
'ssh-rsa'
and
len
(
self
.
parts
)
==
3
:
raise
TypeError
(
"key is not a RSA key"
)
raise
TypeError
(
"key is not a
valid
RSA key"
)
from
pyasn1.codec.der
import
encoder
as
der_encoder
from
pyasn1.codec.der
import
encoder
as
der_encoder
from
pyasn1.type
import
univ
from
pyasn1.type
import
univ
keydata
=
self
.
keydata
e
=
bytes2int
(
self
.
parts
[
1
])
parts
=
[]
n
=
bytes2int
(
self
.
parts
[
2
])
while
keydata
:
dlen
=
struct
.
unpack
(
'>I'
,
keydata
[:
4
])[
0
]
data
,
keydata
=
keydata
[
4
:
4
+
dlen
],
keydata
[
4
+
dlen
:]
parts
.
append
(
data
)
e
=
bytes2int
(
parts
[
1
])
n
=
bytes2int
(
parts
[
2
])
pkcs1_seq
=
univ
.
Sequence
()
pkcs1_seq
=
univ
.
Sequence
()
pkcs1_seq
.
setComponentByPosition
(
0
,
univ
.
Integer
(
n
))
pkcs1_seq
.
setComponentByPosition
(
0
,
univ
.
Integer
(
n
))
pkcs1_seq
.
setComponentByPosition
(
1
,
univ
.
Integer
(
e
))
pkcs1_seq
.
setComponentByPosition
(
1
,
univ
.
Integer
(
e
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment