Update normalise and example for clearsigning

Trailing whitespace must be removed when generating the signature and
must not be included in output.
This commit is contained in:
Stephen Paul Weber
2016-02-24 11:06:36 -05:00
parent 6340379ffe
commit cefaef242d
2 changed files with 17 additions and 2 deletions

View File

@@ -1702,10 +1702,19 @@ class OpenPGP_LiteralDataPacket extends OpenPGP_Packet {
$this->timestamp = isset($opt['timestamp']) ? $opt['timestamp'] : time();
}
function normalize() {
function normalize($clearsign=false) {
if($clearsign && ($this->format != 'u' && $this->format != 't')) {
$this->format = 'u'; // Clearsign must be text
}
if($this->format == 'u' || $this->format == 't') { // Normalize line endings
$this->data = str_replace("\n", "\r\n", str_replace("\r", "\n", str_replace("\r\n", "\n", $this->data)));
}
if($clearsign) {
// When clearsigning, do not sign over trailing whitespace
$this->data = preg_replace('/\s+\r/', "\r", $this->data);
}
}
function read() {