Skip to content

Commit

Permalink
add public function
Browse files Browse the repository at this point in the history
  • Loading branch information
oneplus1000 committed Oct 7, 2016
1 parent b3f9279 commit 9a0d6dc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
10 changes: 10 additions & 0 deletions encryption_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ func (e *EncryptionObj) escape(b []byte) string {
s = strings.Replace(s, "\r", "\\r", -1)
return s
}

//GetObjBuff get buffer
func (e *EncryptionObj) GetObjBuff() *bytes.Buffer {
return e.getObjBuff()
}

//Build build buffer
func (e *EncryptionObj) Build(objID int) error {
return e.build(objID)
}
2 changes: 1 addition & 1 deletion image_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ImageObj struct {
}

func (i *ImageObj) init(funcGetRoot func() *GoPdf) {
//i.getRoot = funcGetRoot

}

func (i *ImageObj) setProtection(p *PDFProtection) {
Expand Down
19 changes: 17 additions & 2 deletions pdf_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ type PDFProtection struct {
encryptionKey []byte
}

//SetProtection set protection infomation
func (p *PDFProtection) SetProtection(permissions int, userPass []byte, ownerPass []byte) error {
return p.setProtection(permissions, userPass, ownerPass)
}

func (p *PDFProtection) setProtection(permissions int, userPass []byte, ownerPass []byte) error {
protection := 192 | permissions
if ownerPass == nil || len(ownerPass) == 0 {
ownerPass = p.randomPass(24)
}
return p.generateencryptionkey(userPass, ownerPass, protection)
return p.generateEncryptionKey(userPass, ownerPass, protection)
}

func (p *PDFProtection) generateencryptionkey(userPass []byte, ownerPass []byte, protection int) error {
func (p *PDFProtection) generateEncryptionKey(userPass []byte, ownerPass []byte, protection int) error {

userPass = append(userPass, protectionPadding...)
userPassWithPadding := userPass[0:32]
Expand All @@ -67,6 +72,11 @@ func (p *PDFProtection) generateencryptionkey(userPass []byte, ownerPass []byte,
return nil
}

//EncryptionObj get Encryption Object
func (p *PDFProtection) EncryptionObj() *EncryptionObj {
return p.encryptionObj()
}

func (p *PDFProtection) encryptionObj() *EncryptionObj {
var en EncryptionObj
en.oValue = p.oValue
Expand Down Expand Up @@ -118,6 +128,11 @@ func (p *PDFProtection) randomPass(strlen int) []byte {
return result
}

//Objectkey create object key from ObjID
func (p *PDFProtection) Objectkey(objID int) []byte {
return p.objectkey(objID)
}

func (p *PDFProtection) objectkey(n int) []byte {
tmp := make([]byte, 8, 8)
binary.LittleEndian.PutUint32(tmp, uint32(n))
Expand Down

0 comments on commit 9a0d6dc

Please sign in to comment.