55 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
66 * SPDX-License-Identifier: AGPL-3.0-only
77 */
8+
89namespace OCA \Encryption ;
910
1011use OC \Files \View ;
1617use OCP \PreConditionNotMetException ;
1718
1819class Recovery {
19- /**
20- * @var null|IUser
21- */
22- protected $ user ;
20+ protected ?IUser $ user ;
2321
24- /**
25- * @param IUserSession $userSession
26- * @param Crypt $crypt
27- * @param KeyManager $keyManager
28- * @param IConfig $config
29- * @param IFile $file
30- * @param View $view
31- */
3222 public function __construct (
3323 IUserSession $ userSession ,
3424 protected Crypt $ crypt ,
@@ -40,11 +30,7 @@ public function __construct(
4030 $ this ->user = ($ userSession ->isLoggedIn ()) ? $ userSession ->getUser () : null ;
4131 }
4232
43- /**
44- * @param string $password
45- * @return bool
46- */
47- public function enableAdminRecovery ($ password ) {
33+ public function enableAdminRecovery (string $ password ): bool {
4834 $ appConfig = $ this ->config ;
4935 $ keyManager = $ this ->keyManager ;
5036
@@ -83,11 +69,7 @@ public function changeRecoveryKeyPassword(string $newPassword, string $oldPasswo
8369 return false ;
8470 }
8571
86- /**
87- * @param string $recoveryPassword
88- * @return bool
89- */
90- public function disableAdminRecovery ($ recoveryPassword ) {
72+ public function disableAdminRecovery (string $ recoveryPassword ): bool {
9173 $ keyManager = $ this ->keyManager ;
9274
9375 if ($ keyManager ->checkRecoveryPassword ($ recoveryPassword )) {
@@ -102,42 +84,34 @@ public function disableAdminRecovery($recoveryPassword) {
10284 * check if recovery is enabled for user
10385 *
10486 * @param string $user if no user is given we check the current logged-in user
105- *
106- * @return bool
10787 */
108- public function isRecoveryEnabledForUser ($ user = '' ) {
88+ public function isRecoveryEnabledForUser (string $ user = '' ): bool {
10989 $ uid = $ user === '' ? $ this ->user ->getUID () : $ user ;
11090 $ recoveryMode = $ this ->config ->getUserValue ($ uid ,
11191 'encryption ' ,
11292 'recoveryEnabled ' ,
113- 0 );
93+ ' 0 ' );
11494
11595 return ($ recoveryMode === '1 ' );
11696 }
11797
11898 /**
11999 * check if recovery is key is enabled by the administrator
120- *
121- * @return bool
122100 */
123- public function isRecoveryKeyEnabled () {
101+ public function isRecoveryKeyEnabled (): bool {
124102 $ enabled = $ this ->config ->getAppValue ('encryption ' , 'recoveryAdminEnabled ' , '0 ' );
125103
126104 return ($ enabled === '1 ' );
127105 }
128106
129- /**
130- * @param string $value
131- * @return bool
132- */
133- public function setRecoveryForUser ($ value ) {
107+ public function setRecoveryForUser (bool $ value ): bool {
134108 try {
135109 $ this ->config ->setUserValue ($ this ->user ->getUID (),
136110 'encryption ' ,
137111 'recoveryEnabled ' ,
138- $ value );
112+ $ value ? ' 1 ' : ' 0 ' );
139113
140- if ($ value === ' 1 ' ) {
114+ if ($ value ) {
141115 $ this ->addRecoveryKeys ('/ ' . $ this ->user ->getUID () . '/files/ ' );
142116 } else {
143117 $ this ->removeRecoveryKeys ('/ ' . $ this ->user ->getUID () . '/files/ ' );
0 commit comments