1717use OCP \PreConditionNotMetException ;
1818
1919class Recovery {
20- /**
21- * @var null|IUser
22- */
23- protected $ user ;
20+ protected ?IUser $ user ;
2421
25- /**
26- * @param IUserSession $userSession
27- * @param Crypt $crypt
28- * @param KeyManager $keyManager
29- * @param IConfig $config
30- * @param IFile $file
31- * @param View $view
32- */
3322 public function __construct (
3423 IUserSession $ userSession ,
3524 protected Crypt $ crypt ,
@@ -41,11 +30,7 @@ public function __construct(
4130 $ this ->user = ($ userSession ->isLoggedIn ()) ? $ userSession ->getUser () : null ;
4231 }
4332
44- /**
45- * @param string $password
46- * @return bool
47- */
48- public function enableAdminRecovery ($ password ) {
33+ public function enableAdminRecovery (string $ password ): bool {
4934 $ appConfig = $ this ->config ;
5035 $ keyManager = $ this ->keyManager ;
5136
@@ -84,11 +69,7 @@ public function changeRecoveryKeyPassword(string $newPassword, string $oldPasswo
8469 return false ;
8570 }
8671
87- /**
88- * @param string $recoveryPassword
89- * @return bool
90- */
91- public function disableAdminRecovery ($ recoveryPassword ) {
72+ public function disableAdminRecovery (string $ recoveryPassword ): bool {
9273 $ keyManager = $ this ->keyManager ;
9374
9475 if ($ keyManager ->checkRecoveryPassword ($ recoveryPassword )) {
@@ -103,42 +84,34 @@ public function disableAdminRecovery($recoveryPassword) {
10384 * check if recovery is enabled for user
10485 *
10586 * @param string $user if no user is given we check the current logged-in user
106- *
107- * @return bool
10887 */
109- public function isRecoveryEnabledForUser ($ user = '' ) {
88+ public function isRecoveryEnabledForUser (string $ user = '' ): bool {
11089 $ uid = $ user === '' ? $ this ->user ->getUID () : $ user ;
11190 $ recoveryMode = $ this ->config ->getUserValue ($ uid ,
11291 'encryption ' ,
11392 'recoveryEnabled ' ,
114- 0 );
93+ ' 0 ' );
11594
11695 return ($ recoveryMode === '1 ' );
11796 }
11897
11998 /**
12099 * check if recovery is key is enabled by the administrator
121- *
122- * @return bool
123100 */
124- public function isRecoveryKeyEnabled () {
101+ public function isRecoveryKeyEnabled (): bool {
125102 $ enabled = $ this ->config ->getAppValue ('encryption ' , 'recoveryAdminEnabled ' , '0 ' );
126103
127104 return ($ enabled === '1 ' );
128105 }
129106
130- /**
131- * @param string $value
132- * @return bool
133- */
134- public function setRecoveryForUser ($ value ) {
107+ public function setRecoveryForUser (bool $ value ): bool {
135108 try {
136109 $ this ->config ->setUserValue ($ this ->user ->getUID (),
137110 'encryption ' ,
138111 'recoveryEnabled ' ,
139- $ value );
112+ $ value ? ' 1 ' : ' 0 ' );
140113
141- if ($ value === ' 1 ' ) {
114+ if ($ value ) {
142115 $ this ->addRecoveryKeys ('/ ' . $ this ->user ->getUID () . '/files/ ' );
143116 } else {
144117 $ this ->removeRecoveryKeys ('/ ' . $ this ->user ->getUID () . '/files/ ' );
0 commit comments