File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -71,4 +71,40 @@ public function signatureValidForPublicKey($publicKey)
71
71
Util::rawBinary ($ publicKey , 32 )
72
72
);
73
73
}
74
+
75
+ /**
76
+ * @param bool $pretty
77
+ * @return string
78
+ * @throws SodiumException
79
+ */
80
+ public function toString ($ pretty = false )
81
+ {
82
+ $ code = $ pretty ? JSON_PRETTY_PRINT : 0 ;
83
+ if ($ this ->signature ) {
84
+ $ signature = sodium_bin2base64 (
85
+ Util::rawBinary ($ this ->getSignature (), 64 ),
86
+ SODIUM_BASE64_VARIANT_URLSAFE
87
+ );
88
+ } else {
89
+ $ signature = '' ;
90
+ }
91
+ return (string ) json_encode (array (
92
+ 'signature ' => $ signature ,
93
+ 'message ' => $ this ->getContents (),
94
+ ), $ code );
95
+ }
96
+
97
+ /**
98
+ * @return string
99
+ */
100
+ public function __toString ()
101
+ {
102
+ try {
103
+ return $ this ->toString ();
104
+ } catch (\Error $ ex ) {
105
+ return '' ;
106
+ } catch (\Exception $ ex ) {
107
+ return '' ;
108
+ }
109
+ }
74
110
}
You can’t perform that action at this time.
0 commit comments