Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F538676
PhabricatorFilesManagementGenerateKeyWorkflow.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
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
(!
phutil_nonempty_string
(
$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
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, May 12, 8:53 AM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
110568
Default Alt Text
PhabricatorFilesManagementGenerateKeyWorkflow.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment