1616use OCP \PreConditionNotMetException ;
1717
1818class Recovery {
19- /**
20- * @var null|IUser
21- */
22- protected $ user ;
19+ protected ?IUser $ user ;
2320
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- */
3221 public function __construct (
3322 IUserSession $ userSession ,
3423 protected Crypt $ crypt ,
@@ -40,11 +29,7 @@ public function __construct(
4029 $ this ->user = ($ userSession ->isLoggedIn ()) ? $ userSession ->getUser () : null ;
4130 }
4231
43- /**
44- * @param string $password
45- * @return bool
46- */
47- public function enableAdminRecovery ($ password ) {
32+ public function enableAdminRecovery (string $ password ): bool {
4833 $ appConfig = $ this ->config ;
4934 $ keyManager = $ this ->keyManager ;
5035
@@ -83,11 +68,7 @@ public function changeRecoveryKeyPassword(string $newPassword, string $oldPasswo
8368 return false ;
8469 }
8570
86- /**
87- * @param string $recoveryPassword
88- * @return bool
89- */
90- public function disableAdminRecovery ($ recoveryPassword ) {
71+ public function disableAdminRecovery (string $ recoveryPassword ): bool {
9172 $ keyManager = $ this ->keyManager ;
9273
9374 if ($ keyManager ->checkRecoveryPassword ($ recoveryPassword )) {
@@ -102,42 +83,34 @@ public function disableAdminRecovery($recoveryPassword) {
10283 * check if recovery is enabled for user
10384 *
10485 * @param string $user if no user is given we check the current logged-in user
105- *
106- * @return bool
10786 */
108- public function isRecoveryEnabledForUser ($ user = '' ) {
87+ public function isRecoveryEnabledForUser (string $ user = '' ): bool {
10988 $ uid = $ user === '' ? $ this ->user ->getUID () : $ user ;
11089 $ recoveryMode = $ this ->config ->getUserValue ($ uid ,
11190 'encryption ' ,
11291 'recoveryEnabled ' ,
113- 0 );
92+ ' 0 ' );
11493
11594 return ($ recoveryMode === '1 ' );
11695 }
11796
11897 /**
11998 * check if recovery is key is enabled by the administrator
120- *
121- * @return bool
12299 */
123- public function isRecoveryKeyEnabled () {
100+ public function isRecoveryKeyEnabled (): bool {
124101 $ enabled = $ this ->config ->getAppValue ('encryption ' , 'recoveryAdminEnabled ' , '0 ' );
125102
126103 return ($ enabled === '1 ' );
127104 }
128105
129- /**
130- * @param string $value
131- * @return bool
132- */
133- public function setRecoveryForUser ($ value ) {
106+ public function setRecoveryForUser (bool $ value ): bool {
134107 try {
135108 $ this ->config ->setUserValue ($ this ->user ->getUID (),
136109 'encryption ' ,
137110 'recoveryEnabled ' ,
138- $ value );
111+ $ value ? ' 1 ' : ' 0 ' );
139112
140- if ($ value === ' 1 ' ) {
113+ if ($ value ) {
141114 $ this ->addRecoveryKeys ('/ ' . $ this ->user ->getUID () . '/files/ ' );
142115 } else {
143116 $ this ->removeRecoveryKeys ('/ ' . $ this ->user ->getUID () . '/files/ ' );
0 commit comments