22
33declare (strict_types=1 );
44
5- namespace Proget ;
5+ namespace Proget \ Samsung \ KnoxToken ;
66
77use Firebase \JWT \JWT ;
88use Ramsey \Uuid \Uuid ;
@@ -13,7 +13,7 @@ class KnoxToken
1313
1414 public static function signClientIdentifier (string $ clientIdentifier , string $ certificatePath ): string
1515 {
16- $ certificate = self :: loadCertificate ($ certificatePath );
16+ $ certificate = Certificate:: fromPath ($ certificatePath );
1717
1818 return JWT ::encode ([
1919 'clientIdentifier ' => $ clientIdentifier ,
@@ -25,7 +25,7 @@ public static function signClientIdentifier(string $clientIdentifier, string $ce
2525
2626 public static function signAccessToken (string $ accessToken , string $ certificatePath ): string
2727 {
28- $ certificate = self :: loadCertificate ($ certificatePath );
28+ $ certificate = Certificate:: fromPath ($ certificatePath );
2929
3030 return JWT ::encode ([
3131 'accessToken ' => $ accessToken ,
@@ -34,18 +34,4 @@ public static function signAccessToken(string $accessToken, string $certificateP
3434 'jti ' => Uuid::uuid1 ()->toString ().Uuid::uuid1 ()->toString ()
3535 ], $ certificate ->privateKeyPem (), 'RS512 ' );
3636 }
37-
38- public static function loadCertificate (string $ certificatePath ): Certificate
39- {
40- if (!file_exists ($ certificatePath )) {
41- throw new \RuntimeException (sprintf ('Missing certificate file at %s ' , $ certificatePath ));
42- }
43- $ certificate = json_decode (file_get_contents ($ certificatePath ), true );
44-
45- if (!isset ($ certificate ['Public ' ], $ certificate ['Private ' ])) {
46- throw new \RuntimeException (sprintf ('Invalid certificate file at %s ' , $ certificatePath ));
47- }
48-
49- return new Certificate ($ certificate ['Public ' ], $ certificate ['Private ' ]);
50- }
5137}
0 commit comments