2020-09-28 23:18:17 +00:00

108 lines
14 KiB
Go

//
// Copyright 2020 FoxyUtils ehf. All rights reserved.
//
// This is a commercial product and requires a license to operate.
// A trial license can be obtained at https://unidoc.io
//
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
//
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
package crypt ;import (_fe "crypto/aes";_g "crypto/cipher";_fd "crypto/md5";_c "crypto/rand";_ec "crypto/rc4";_a "fmt";_ff "github.com/unidoc/unipdf/v3/common";_ab "github.com/unidoc/unipdf/v3/core/security";_e "io";);func init (){_gfg ("\u0041\u0045\u0053V\u0032",_abf )};func _abf (_ac FilterDict )(Filter ,error ){if _ac .Length ==128{_ff .Log .Debug ("\u0041\u0045S\u0056\u0032\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_ac .Length );_ac .Length /=8;};if _ac .Length !=0&&_ac .Length !=16{return nil ,_a .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0032\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_ac .Length );};return filterAESV2 {},nil ;};type filterIdentity struct{};
// KeyLength implements Filter interface.
func (filterAESV3 )KeyLength ()int {return 256/8};
// NewFilter creates CryptFilter from a corresponding dictionary.
func NewFilter (d FilterDict )(Filter ,error ){_fbe ,_fbf :=_bae (d .CFM );if _fbf !=nil {return nil ,_fbf ;};_ca ,_fbf :=_fbe (d );if _fbf !=nil {return nil ,_fbf ;};return _ca ,nil ;};
// KeyLength implements Filter interface.
func (_bbe filterV2 )KeyLength ()int {return _bbe ._ade };
// NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).
func NewFilterAESV3 ()Filter {_fa ,_ce :=_dg (FilterDict {});if _ce !=nil {_ff .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0033\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ce );return filterAESV3 {};};return _fa ;};
// FilterDict represents information from a CryptFilter dictionary.
type FilterDict struct{CFM string ;AuthEvent _ab .AuthEvent ;Length int ;};
// Name implements Filter interface.
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};var _ Filter =filterAESV2 {};func init (){_gfg ("\u0041\u0045\u0053V\u0033",_dg )};type filterV2 struct{_ade int };
// MakeKey implements Filter interface.
func (_ge filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _ffb (objNum ,genNum ,ekey ,false );};
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
func NewFilterV2 (length int )Filter {_gc ,_ef :=_cd (FilterDict {Length :length });if _ef !=nil {_ff .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020R\u0043\u0034\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ef );return filterV2 {_ade :length };};return _gc ;};
// MakeKey implements Filter interface.
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _ffb (objNum ,genNum ,ekey ,true );};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_gg ,_bb :=_fe .NewCipher (okey );if _bb !=nil {return nil ,_bb ;};if len (buf )< 16{_ff .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf );return buf ,_a .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_ga :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_ff .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_ga ),_ga );_ff .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_a .Errorf ("\u0041\u0045\u0053\u0020\u0062\u0075\u0066\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069p\u006c\u0065\u0020\u006f\u0066 \u0031\u0036 \u0028\u0025\u0064\u0029",len (buf ));};_ecf :=_g .NewCBCDecrypter (_gg ,_ga );_ff .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_ff .Log .Trace ("\u0063\u0068\u006f\u0070\u0020\u0041\u0045\u0053\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u0020\u0028\u0025\u0064\u0029\u003a \u0025\u0020\u0078",len (buf ),buf );_ecf .CryptBlocks (buf ,buf );_ff .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_ff .Log .Trace ("\u0045\u006d\u0070\u0074\u0079\u0020b\u0075\u0066\u002c\u0020\u0072\u0065\u0074\u0075\u0072\u006e\u0069\u006e\u0067 \u0065\u006d\u0070\u0074\u0079\u0020\u0073t\u0072\u0069\u006e\u0067");return buf ,nil ;};_agd :=int (buf [len (buf )-1]);if _agd > len (buf ){_ff .Log .Debug ("\u0049\u006c\u006c\u0065g\u0061\u006c\u0020\u0070\u0061\u0064\u0020\u006c\u0065\u006eg\u0074h\u0020\u0028\u0025\u0064\u0020\u003e\u0020%\u0064\u0029",_agd ,len (buf ));return buf ,_a .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_agd ];return buf ,nil ;};type filterAESV2 struct{filterAES };type filterFunc func (_cca FilterDict )(Filter ,error );
// KeyLength implements Filter interface.
func (filterAESV2 )KeyLength ()int {return 128/8};
// Name implements Filter interface.
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};
// Filter is a common interface for crypt filter methods.
type Filter interface{
// Name returns a name of the filter that should be used in CFM field of Encrypt dictionary.
Name ()string ;
// KeyLength returns a length of the encryption key in bytes.
KeyLength ()int ;
// PDFVersion reports the minimal version of PDF document that introduced this filter.
PDFVersion ()[2]int ;
// HandlerVersion reports V and R parameters that should be used for this filter.
HandlerVersion ()(V ,R int );
// MakeKey generates a object encryption key based on file encryption key and object numbers.
// Used only for legacy filters - AESV3 doesn't change the key for each object.
MakeKey (_db ,_gdg uint32 ,_cff []byte )([]byte ,error );
// EncryptBytes encrypts a buffer using object encryption key, as returned by MakeKey.
// Implementation may reuse a buffer and encrypt data in-place.
EncryptBytes (_deg []byte ,_ead []byte )([]byte ,error );
// DecryptBytes decrypts a buffer using object encryption key, as returned by MakeKey.
// Implementation may reuse a buffer and decrypt data in-place.
DecryptBytes (_bg []byte ,_efa []byte )([]byte ,error );};func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_eb ,_dc :=_fe .NewCipher (okey );if _dc !=nil {return nil ,_dc ;};_ff .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _fdg =_fe .BlockSize ;_af :=_fdg -len (buf )%_fdg ;for _ag :=0;_ag < _af ;_ag ++{buf =append (buf ,byte (_af ));};_ff .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_cf :=make ([]byte ,_fdg +len (buf ));_da :=_cf [:_fdg ];if _ ,_b :=_e .ReadFull (_c .Reader ,_da );_b !=nil {return nil ,_b ;};_fc :=_g .NewCBCEncrypter (_eb ,_da );_fc .CryptBlocks (_cf [_fdg :],buf );buf =_cf ;_ff .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};
// Name implements Filter interface.
func (filterV2 )Name ()string {return "\u0056\u0032"};func init (){_gfg ("\u0056\u0032",_cd )};
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
func NewFilterAESV2 ()Filter {_cc ,_cb :=_abf (FilterDict {});if _cb !=nil {_ff .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_cb );return filterAESV2 {};};return _cc ;};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};
// MakeKey implements Filter interface.
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };
// HandlerVersion implements Filter interface.
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};
// HandlerVersion implements Filter interface.
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};
// HandlerVersion implements Filter interface.
func (_gag filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};var _ Filter =filterV2 {};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};
// PDFVersion implements Filter interface.
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};
// EncryptBytes implements Filter interface.
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_df ,_afg :=_ec .NewCipher (okey );if _afg !=nil {return nil ,_afg ;};_ff .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_df .XORKeyStream (buf ,buf );_ff .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};var _ Filter =filterAESV3 {};func _cd (_de FilterDict )(Filter ,error ){if _de .Length %8!=0{return nil ,_a .Errorf ("\u0063\u0072\u0079p\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020o\u0066\u0020\u0038\u0020\u0028\u0025\u0064\u0029",_de .Length );};if _de .Length < 5||_de .Length > 16{if _de .Length ==40||_de .Length ==64||_de .Length ==128{_ff .Log .Debug ("\u0053\u0054\u0041\u004e\u0044AR\u0044\u0020V\u0049\u004f\u004c\u0041\u0054\u0049\u004f\u004e\u003a\u0020\u0043\u0072\u0079\u0070\u0074\u0020\u004c\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072s\u0020\u0074\u006f \u0062\u0065\u0020\u0069\u006e\u0020\u0062\u0069\u0074\u0073\u0020\u0072\u0061t\u0068\u0065\u0072\u0020\u0074h\u0061\u006e\u0020\u0062\u0079\u0074\u0065\u0073\u0020-\u0020\u0061s\u0073u\u006d\u0069\u006e\u0067\u0020\u0062\u0069t\u0073\u0020\u0028\u0025\u0064\u0029",_de .Length );_de .Length /=8;}else {return nil ,_a .Errorf ("\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u006e\u006f\u0074\u0020\u0069\u006e \u0072\u0061\u006e\u0067\u0065\u0020\u0034\u0030\u0020\u002d\u00201\u0032\u0038\u0020\u0062\u0069\u0074\u0020\u0028\u0025\u0064\u0029",_de .Length );};};return filterV2 {_ade :_de .Length },nil ;};type filterAESV3 struct{filterAES };func (filterIdentity )KeyLength ()int {return 0};func _ffb (_fea ,_fb uint32 ,_feag []byte ,_gac bool )([]byte ,error ){_dcd :=make ([]byte ,len (_feag )+5);for _cbb :=0;_cbb < len (_feag );_cbb ++{_dcd [_cbb ]=_feag [_cbb ];};for _gd :=0;_gd < 3;_gd ++{_ae :=byte ((_fea >>uint32 (8*_gd ))&0xff);_dcd [_gd +len (_feag )]=_ae ;};for _def :=0;_def < 2;_def ++{_eg :=byte ((_fb >>uint32 (8*_def ))&0xff);_dcd [_def +len (_feag )+3]=_eg ;};if _gac {_dcd =append (_dcd ,0x73);_dcd =append (_dcd ,0x41);_dcd =append (_dcd ,0x6C);_dcd =append (_dcd ,0x54);};_ad :=_fd .New ();_ad .Write (_dcd );_ced :=_ad .Sum (nil );if len (_feag )+5< 16{return _ced [0:len (_feag )+5],nil ;};return _ced ,nil ;};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func _dg (_ea FilterDict )(Filter ,error ){if _ea .Length ==256{_ff .Log .Debug ("\u0041\u0045S\u0056\u0033\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_ea .Length );_ea .Length /=8;};if _ea .Length !=0&&_ea .Length !=32{return nil ,_a .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0033\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_ea .Length );};return filterAESV3 {},nil ;};func _bae (_egd string )(filterFunc ,error ){_cce :=_cba [string (_egd )];if _cce ==nil {return nil ,_a .Errorf ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u0072\u0079p\u0074 \u0066\u0069\u006c\u0074\u0065\u0072\u003a \u0025\u0071",_egd );};return _cce ,nil ;};
// PDFVersion implements Filter interface.
func (_aef filterV2 )PDFVersion ()[2]int {return [2]int {}};
// PDFVersion implements Filter interface.
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};
// DecryptBytes implements Filter interface.
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_cfa ,_eff :=_ec .NewCipher (okey );if _eff !=nil {return nil ,_eff ;};_ff .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_cfa .XORKeyStream (buf ,buf );_ff .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};type filterAES struct{};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };func _gfg (_bgb string ,_ba filterFunc ){if _ ,_age :=_cba [_bgb ];_age {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_cba [_bgb ]=_ba ;};var (_cba =make (map[string ]filterFunc ););
// NewIdentity creates an identity filter that bypasses all data without changes.
func NewIdentity ()Filter {return filterIdentity {}};