FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
hack-codegen/src/SignedSource.php at master · numb4/hack-codegen · GitHub
numb4
/
hack-codegen
Public
forked from
hhvm/hack-codegen
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
hack-codegen
/
src
/
SignedSource.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
76 lines (73 loc) · 2.42 KB
Breadcrumbs
hack-codegen
/
src
/
SignedSource.php
Copy path
File metadata and controls
76 lines (73 loc) · 2.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<
?
hh
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace
Facebook\HackCodegen
;
/**
* Designate machine-generated code so tools can distinguish it from
* human-generated code, and prevent manual edits of machine-generated code by
* embedding a simple checksum in generated source files.
*
*
* = Generating Signed Source =
*
* When generating source, use SignedSource to sign the file. This will prevent
* it from being checked in if it is manually edited. Signing is a two step
* process:
*
* 1. Call SignedSource::getSigningToken() and embed the return string
* somewhere in your source file (generally, in a header comment).
* 2. After generating the file, call SignedSource::signFile($file).
*
* For example:
*
* $signature_token = SignedSource::getSigningToken();
* $generated_file = <<<EODOC
* /**
* * This file is generated. Do not modify it manually!
* *
* * {$signature_token}
* *
* ...
*
* $signed_file = SignedSource::signFile($generated_file);
* Filesystem::writeFileIfChanged('/path/to/generated/file', $signed_file);
*
*
* = Verifying Signed Source =
*
* Use SignedSource::isSigned() to determine if a file has a signature or not.
* Then, use SignedSource::verifySignature() to verify a file's signature:
*
* $is_signed = SignedSource::isSigned($questionable_file);
* if ($is_signed) {
* $intact = SignedSource::verifySignature($questionable_file);
* if ($intact) {
* echo 'File is signed with correct signature.';
* } else {
* echo 'File is signed with invalid signature. It has been edited!';
* }
* }
*
*/
final
class
SignedSource
extends
SignedSourceBase
{
protected
static
function
getTokenName
() {
return
'
generated
'
;
}
/**
* Get the text for a doc block that can be used for an autogenerated file.
* If a comment is set, it will be included in the doc block.
*/
public
static
function
getDocBlock
(?
string
$comment
=
null
) {
$comment
=
$comment
?
$comment
.
"
\n\n
"
:
null
;
return
"
This file is generated. Do not modify it manually!
\n\n
"
.
$comment
.
self
::
getSigningToken();
}
}
Back
|
FazBrowse Home
|
New Git URL