2014-06-16 07:32:57 +07:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2016-07-31 12:35:06 +04:00
|
|
|
* @copyright 2010-2016 PHPWord contributors
|
2014-06-16 07:32:57 +07:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Metadata;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Document protection class
|
|
|
|
|
*
|
|
|
|
|
* @since 0.12.0
|
|
|
|
|
* @link http://www.datypic.com/sc/ooxml/t-w_CT_DocProtect.html
|
|
|
|
|
*/
|
|
|
|
|
class Protection
|
|
|
|
|
{
|
|
|
|
|
/**
|
2017-03-10 13:28:32 +01:00
|
|
|
* Editing restriction none|readOnly|comments|trackedChanges|forms
|
2014-06-16 07:32:57 +07:00
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
* @link http://www.datypic.com/sc/ooxml/a-w_edit-1.html
|
|
|
|
|
*/
|
|
|
|
|
private $editing;
|
|
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
/**
|
2017-03-13 16:22:04 +01:00
|
|
|
* password
|
2017-03-10 15:44:13 +01:00
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2017-03-10 16:24:52 +01:00
|
|
|
private $password = '';
|
2017-03-10 13:28:32 +01:00
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
/**
|
|
|
|
|
* Number of hashing iterations
|
|
|
|
|
*
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
2017-03-10 16:57:42 +01:00
|
|
|
private $spinCount = 100000;
|
2017-03-10 13:28:32 +01:00
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
/**
|
2017-03-10 16:24:52 +01:00
|
|
|
* Algorithm-SID (see to \PhpOffice\PhpWord\Writer\Word2007\Part\Settings::$algorithmMapping)
|
2017-03-10 15:44:13 +01:00
|
|
|
*
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
2017-03-10 16:57:42 +01:00
|
|
|
private $mswordAlgorithmSid = 4;
|
2017-03-10 13:28:32 +01:00
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
/**
|
2017-03-13 16:22:04 +01:00
|
|
|
* salt
|
2017-03-10 15:44:13 +01:00
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2017-03-10 16:24:52 +01:00
|
|
|
private $salt = '';
|
2017-03-10 13:28:32 +01:00
|
|
|
|
2014-06-16 07:32:57 +07:00
|
|
|
/**
|
|
|
|
|
* Create a new instance
|
|
|
|
|
*
|
|
|
|
|
* @param string $editing
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($editing = null)
|
|
|
|
|
{
|
|
|
|
|
$this->setEditing($editing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get editing protection
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getEditing()
|
|
|
|
|
{
|
|
|
|
|
return $this->editing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set editing protection
|
|
|
|
|
*
|
|
|
|
|
* @param string $editing
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setEditing($editing = null)
|
|
|
|
|
{
|
|
|
|
|
$this->editing = $editing;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2017-03-10 13:28:32 +01:00
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
/**
|
2017-03-13 16:22:04 +01:00
|
|
|
* Get password
|
2017-03-10 15:44:13 +01:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2017-03-10 13:28:32 +01:00
|
|
|
public function getPassword()
|
|
|
|
|
{
|
|
|
|
|
return $this->password;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
/**
|
|
|
|
|
* Set password
|
|
|
|
|
*
|
|
|
|
|
* @param $password
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
2017-03-10 13:28:32 +01:00
|
|
|
public function setPassword($password)
|
|
|
|
|
{
|
2017-03-10 16:24:52 +01:00
|
|
|
$this->password = $password;
|
2017-03-10 13:28:32 +01:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
/**
|
|
|
|
|
* Get count for hash iterations
|
|
|
|
|
*
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
2017-03-10 13:28:32 +01:00
|
|
|
public function getSpinCount()
|
|
|
|
|
{
|
|
|
|
|
return $this->spinCount;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
/**
|
|
|
|
|
* Set count for hash iterations
|
|
|
|
|
*
|
|
|
|
|
* @param $spinCount
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
2017-03-10 13:28:32 +01:00
|
|
|
public function setSpinCount($spinCount)
|
|
|
|
|
{
|
|
|
|
|
$this->spinCount = $spinCount;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
/**
|
|
|
|
|
* Get algorithm-sid
|
|
|
|
|
*
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
2017-03-10 16:57:42 +01:00
|
|
|
public function getMswordAlgorithmSid()
|
2017-03-10 13:28:32 +01:00
|
|
|
{
|
2017-03-10 16:57:42 +01:00
|
|
|
return $this->mswordAlgorithmSid;
|
2017-03-10 13:28:32 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
/**
|
2017-03-10 16:24:52 +01:00
|
|
|
* Set algorithm-sid (see \PhpOffice\PhpWord\Writer\Word2007\Part\Settings::$algorithmMapping)
|
2017-03-10 15:44:13 +01:00
|
|
|
*
|
2017-03-10 16:57:42 +01:00
|
|
|
* @param $mswordAlgorithmSid
|
2017-03-10 15:44:13 +01:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2017-03-10 16:57:42 +01:00
|
|
|
public function setMswordAlgorithmSid($mswordAlgorithmSid)
|
2017-03-10 13:28:32 +01:00
|
|
|
{
|
2017-03-10 16:57:42 +01:00
|
|
|
$this->mswordAlgorithmSid = $mswordAlgorithmSid;
|
2017-03-10 13:28:32 +01:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
/**
|
2017-03-13 16:22:04 +01:00
|
|
|
* Get salt
|
2017-03-10 15:44:13 +01:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getSalt()
|
2017-03-10 13:28:32 +01:00
|
|
|
{
|
2017-03-10 15:44:13 +01:00
|
|
|
return $this->salt;
|
2017-03-10 13:28:32 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
/**
|
2017-03-13 16:22:04 +01:00
|
|
|
* Set salt. Salt HAS to be 16 characters, or an exception will be thrown.
|
2017-03-10 15:44:13 +01:00
|
|
|
*
|
|
|
|
|
* @param $salt
|
|
|
|
|
* @return self
|
2017-03-13 16:22:04 +01:00
|
|
|
* @throws \InvalidArgumentException
|
2017-03-10 15:44:13 +01:00
|
|
|
*/
|
|
|
|
|
public function setSalt($salt)
|
2017-03-10 13:28:32 +01:00
|
|
|
{
|
2017-03-13 16:22:04 +01:00
|
|
|
if ($salt !== null && strlen($salt) !== 16){
|
|
|
|
|
throw new \InvalidArgumentException('salt has to be of exactly 16 bytes length');
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 15:44:13 +01:00
|
|
|
$this->salt = $salt;
|
|
|
|
|
|
|
|
|
|
return $this;
|
2017-03-10 13:28:32 +01:00
|
|
|
}
|
2014-06-16 07:32:57 +07:00
|
|
|
}
|