Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93527731
PhabricatorAuthSSHPublicKey.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 29, 11:40
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Dec 1, 11:40 (2 d)
Engine
blob
Format
Raw Data
Handle
22657995
Attached To
rPH Phabricator
PhabricatorAuthSSHPublicKey.php
View Options
<?php
/**
* Data structure representing a raw public key.
*/
final
class
PhabricatorAuthSSHPublicKey
extends
Phobject
{
private
$type
;
private
$body
;
private
$comment
;
private
function
__construct
()
{
// <internal>
}
public
static
function
newFromRawKey
(
$entire_key
)
{
$entire_key
=
trim
(
$entire_key
);
if
(!
strlen
(
$entire_key
))
{
throw
new
Exception
(
pht
(
'No public key was provided.'
));
}
$parts
=
str_replace
(
"
\n
"
,
''
,
$entire_key
);
// The third field (the comment) can have spaces in it, so split this
// into a maximum of three parts.
$parts
=
preg_split
(
'/
\s
+/'
,
$parts
,
3
);
if
(
preg_match
(
'/private
\s
*key/i'
,
$entire_key
))
{
// Try to give the user a better error message if it looks like
// they uploaded a private key.
throw
new
Exception
(
pht
(
'Provide a public key, not a private key!'
));
}
switch
(
count
(
$parts
))
{
case
1
:
throw
new
Exception
(
pht
(
'Provided public key is not properly formatted.'
));
case
2
:
// Add an empty comment part.
$parts
[]
=
''
;
break
;
case
3
:
// This is the expected case.
break
;
}
list
(
$type
,
$body
,
$comment
)
=
$parts
;
$recognized_keys
=
array
(
'ssh-dsa'
,
'ssh-dss'
,
'ssh-rsa'
,
'ecdsa-sha2-nistp256'
,
'ecdsa-sha2-nistp384'
,
'ecdsa-sha2-nistp521'
,
);
if
(!
in_array
(
$type
,
$recognized_keys
))
{
$type_list
=
implode
(
', '
,
$recognized_keys
);
throw
new
Exception
(
pht
(
'Public key type should be one of: %s'
,
$type_list
));
}
$public_key
=
new
PhabricatorAuthSSHPublicKey
();
$public_key
->
type
=
$type
;
$public_key
->
body
=
$body
;
$public_key
->
comment
=
$comment
;
return
$public_key
;
}
public
function
getType
()
{
return
$this
->
type
;
}
public
function
getBody
()
{
return
$this
->
body
;
}
public
function
getComment
()
{
return
$this
->
comment
;
}
}
Event Timeline
Log In to Comment