forked from signintech/gopdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryption_obj.go
43 lines (36 loc) · 969 Bytes
/
encryption_obj.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package gopdf
import (
"fmt"
"io"
"strings"
)
// EncryptionObj encryption object res
type EncryptionObj struct {
uValue []byte //U entry in pdf document
oValue []byte //O entry in pdf document
pValue int //P entry in pdf document
}
func (e *EncryptionObj) init(func() *GoPdf) {
}
func (e *EncryptionObj) getType() string {
return "Encryption"
}
func (e *EncryptionObj) write(w io.Writer, objID int) error {
io.WriteString(w, "<<\n")
io.WriteString(w, "/Filter /Standard\n")
io.WriteString(w, "/V 1\n")
io.WriteString(w, "/R 2\n")
fmt.Fprintf(w, "/O (%s)\n", e.escape(e.oValue))
fmt.Fprintf(w, "/U (%s)\n", e.escape(e.uValue))
fmt.Fprintf(w, "/P %d\n", e.pValue)
io.WriteString(w, ">>\n")
return nil
}
func (e *EncryptionObj) escape(b []byte) string {
s := string(b)
s = strings.Replace(s, "\\", "\\\\", -1)
s = strings.Replace(s, "(", "\\(", -1)
s = strings.Replace(s, ")", "\\)", -1)
s = strings.Replace(s, "\r", "\\r", -1)
return s
}