Skip to content

Commit 4e6df2d

Browse files
fix generated example
1 parent ef6ebe1 commit 4e6df2d

2 files changed

Lines changed: 18 additions & 39 deletions

File tree

docpages/basic-language-reference/functions/string/SIGNS.md

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,16 @@ The returned signature may be written to disk using \ref BINWRITE "BINWRITE" and
1313
### Examples
1414

1515
```basic
16-
REM Sign a package
17-
16+
REM First generate signature
1817
SIG$ = SIGN$("editor.gz", "packages.key")
19-
18+
REM allocate memory for the signature as a raw buffer
19+
m = MEMALLOC(64)
2020
F = OPENOUT("editor.gz.sig")
21-
BINWRITE F, SIG$
22-
CLOSE #F
23-
```
24-
25-
```basic
26-
REM Sign and immediately verify a package
27-
28-
SIG$ = SIGN$("game.gz", "packages.key")
29-
30-
F = OPENOUT("game.gz.sig")
31-
BINWRITE F, SIG$
32-
CLOSE #F
33-
34-
IF VERIFY("game.gz", "game.gz.sig", "packages.pem") THEN
35-
{
36-
PRINT "Signature valid"
37-
}
21+
REM Convert the string to a raw buffer
22+
n = STRINGTOBUFFER(SIG$, m, 64)
23+
REM write it to the file
24+
BINWRITE F, m, n
25+
CLOSE F
3826
```
3927

4028
---
@@ -44,7 +32,7 @@ IF VERIFY("game.gz", "game.gz.sig", "packages.pem") THEN
4432
* `file$` is the file to sign.
4533
* `privatekey$` is a PEM private key file.
4634
* Returns an escaped detached Ed25519 signature string.
47-
* The returned string is safe to store using normal BASIC file functions.
35+
* The returned string should be converted to a binary buffer before storage.
4836
* Detached signatures are normally stored with a `.sig` extension.
4937
* Signatures generated by `SIGN$` may be verified using \ref VERIFY "VERIFY".
5038

docs/SIGNS.html

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,33 +129,24 @@
129129
<hr />
130130
<h3 class="doxsection"><a class="anchor" id="examples-152"></a>
131131
Examples</h3>
132-
<div class="fragment"><div class="line">REM Sign a package</div>
133-
<div class="line"> </div>
132+
<div class="fragment"><div class="line">REM First generate signature</div>
134133
<div class="line">SIG$ = SIGN$(&quot;editor.gz&quot;, &quot;packages.key&quot;)</div>
135-
<div class="line"> </div>
134+
<div class="line">REM allocate memory for the signature as a raw buffer</div>
135+
<div class="line">m = MEMALLOC(64)</div>
136136
<div class="line">F = OPENOUT(&quot;editor.gz.sig&quot;)</div>
137-
<div class="line">BINWRITE F, SIG$</div>
138-
<div class="line">CLOSE #F</div>
139-
</div><!-- fragment --><div class="fragment"><div class="line">REM Sign and immediately verify a package</div>
140-
<div class="line"> </div>
141-
<div class="line">SIG$ = SIGN$(&quot;game.gz&quot;, &quot;packages.key&quot;)</div>
142-
<div class="line"> </div>
143-
<div class="line">F = OPENOUT(&quot;game.gz.sig&quot;)</div>
144-
<div class="line">BINWRITE F, SIG$</div>
145-
<div class="line">CLOSE #F</div>
146-
<div class="line"> </div>
147-
<div class="line">IF VERIFY(&quot;game.gz&quot;, &quot;game.gz.sig&quot;, &quot;packages.pem&quot;) THEN</div>
148-
<div class="line">{</div>
149-
<div class="line"> PRINT &quot;Signature valid&quot;</div>
150-
<div class="line">}</div>
137+
<div class="line">REM Convert the string to a raw buffer</div>
138+
<div class="line">n = STRINGTOBUFFER(SIG$, m, 64)</div>
139+
<div class="line">REM write it to the file</div>
140+
<div class="line">BINWRITE F, m, n</div>
141+
<div class="line">CLOSE F</div>
151142
</div><!-- fragment --><hr />
152143
<h3 class="doxsection"><a class="anchor" id="notes-149"></a>
153144
Notes</h3>
154145
<ul>
155146
<li><span class="tt">file$</span> is the file to sign.</li>
156147
<li><span class="tt">privatekey$</span> is a PEM private key file.</li>
157148
<li>Returns an escaped detached Ed25519 signature string.</li>
158-
<li>The returned string is safe to store using normal BASIC file functions.</li>
149+
<li>The returned string should be converted to a binary buffer before storage.</li>
159150
<li>Detached signatures are normally stored with a <span class="tt">.sig</span> extension.</li>
160151
<li>Signatures generated by <span class="tt">SIGN$</span> may be verified using <a class="el" href="VERIFY.html">VERIFY</a>.</li>
161152
</ul>

0 commit comments

Comments
 (0)