Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F94150167
PhabricatorFilesManagementGenerateKeyWorkflow.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
Wed, Dec 4, 07:23
Size
1 KB
Mime Type
text/x-php
Expires
Fri, Dec 6, 07:23 (1 d, 12 h)
Engine
blob
Format
Raw Data
Handle
22743471
Attached To
rPH Phabricator
PhabricatorFilesManagementGenerateKeyWorkflow.php
View Options
<?php
final
class
PhabricatorFilesManagementGenerateKeyWorkflow
extends
PhabricatorFilesManagementWorkflow
{
protected
function
didConstruct
()
{
$this
->
setName
(
'generate-key'
)
->
setSynopsis
(
pht
(
'Generate an encryption key.'
))
->
setArguments
(
array
(
array
(
'name'
=>
'type'
,
'param'
=>
'keytype'
,
'help'
=>
pht
(
'Select the type of key to generate.'
),
),
));
}
public
function
execute
(
PhutilArgumentParser
$args
)
{
$type
=
$args
->
getArg
(
'type'
);
if
(!
strlen
(
$type
))
{
throw
new
PhutilArgumentUsageException
(
pht
(
'Specify the type of key to generate with --type.'
));
}
$format
=
PhabricatorFileStorageFormat
::
getFormat
(
$type
);
if
(!
$format
)
{
throw
new
PhutilArgumentUsageException
(
pht
(
'No key type "%s" exists.'
,
$type
));
}
if
(!
$format
->
canGenerateNewKeyMaterial
())
{
throw
new
PhutilArgumentUsageException
(
pht
(
'Storage format "%s" can not generate keys.'
,
$format
->
getStorageFormatName
()));
}
$material
=
$format
->
generateNewKeyMaterial
();
$structure
=
array
(
'name'
=>
'generated-key-'
.
Filesystem
::
readRandomCharacters
(
12
),
'type'
=>
$type
,
'material.base64'
=>
$material
,
);
$json
=
id
(
new
PhutilJSON
())->
encodeFormatted
(
$structure
);
echo
tsprintf
(
"%s: %s
\n\n
%B
\n
"
,
pht
(
'Key Material'
),
$format
->
getStorageFormatName
(),
$json
);
return
0
;
}
}
Event Timeline
Log In to Comment