unipdf/common/license/license.go

16 lines
15 KiB
Go
Raw Normal View History

2020-08-27 21:45:09 +00:00
//
// 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 license helps manage commercial licenses and check if they are valid for the version of unidoc used.
2020-10-12 14:17:59 +00:00
package license ;import (_a "crypto";_cc "crypto/rand";_bc "crypto/rsa";_cf "crypto/sha512";_b "crypto/x509";_gc "encoding/base64";_ed "encoding/json";_cg "encoding/pem";_g "fmt";_fd "github.com/unidoc/unipdf/v3/common";_ad "io/ioutil";_f "os";_c "strings";_fg "time";);func GetLicenseKey ()*LicenseKey {if _fdg ==nil {return nil ;};_fff :=*_fdg ;return &_fff ;};var _ebc =_fg .Date (2020,1,1,0,0,0,0,_fg .UTC );func _def (_bea string ,_adc string ,_ga string )(string ,error ){_gbd :=_c .Index (_ga ,_bea );if _gbd ==-1{return "",_g .Errorf ("\u0068\u0065a\u0064\u0065\u0072 \u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_af :=_c .Index (_ga ,_adc );if _af ==-1{return "",_g .Errorf ("\u0066\u006fo\u0074\u0065\u0072 \u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_bg :=_gbd +len (_bea )+1;return _ga [_bg :_af -1],nil ;};func MakeUnlicensedKey ()*LicenseKey {_efd :=LicenseKey {};_efd .CustomerName ="\u0055\u006e\u006c\u0069\u0063\u0065\u006e\u0073\u0065\u0064";_efd .Tier =LicenseTierUnlicensed ;_efd .CreatedAt =_fg .Now ().UTC ();_efd .CreatedAtInt =_efd .CreatedAt .Unix ();return &_efd ;};func (_dg *LicenseKey )ToString ()string {_eaa :=_g .Sprintf ("\u004ci\u0063e\u006e\u0073\u0065\u0020\u0049\u0064\u003a\u0020\u0025\u0073\u000a",_dg .LicenseId );_eaa +=_g .Sprintf ("\u0043\u0075s\u0074\u006f\u006de\u0072\u0020\u0049\u0064\u003a\u0020\u0025\u0073\u000a",_dg .CustomerId );_eaa +=_g .Sprintf ("\u0043u\u0073t\u006f\u006d\u0065\u0072\u0020N\u0061\u006de\u003a\u0020\u0025\u0073\u000a",_dg .CustomerName );_eaa +=_g .Sprintf ("\u0054i\u0065\u0072\u003a\u0020\u0025\u0073\n",_dg .Tier );_eaa +=_g .Sprintf ("\u0043r\u0065a\u0074\u0065\u0064\u0020\u0041\u0074\u003a\u0020\u0025\u0073\u000a",_fd .UtcTimeFormat (_dg .CreatedAt ));if _dg .ExpiresAt ==nil {_eaa +=_g .Sprintf ("\u0045x\u0070i\u0072\u0065\u0073\u0020\u0041t\u003a\u0020N\u0065\u0076\u0065\u0072\u000a");}else {_eaa +=_g .Sprintf ("\u0045x\u0070i\u0072\u0065\u0073\u0020\u0041\u0074\u003a\u0020\u0025\u0073\u000a",_fd .UtcTimeFormat (*_dg .ExpiresAt ));};_eaa +=_g .Sprintf ("\u0043\u0072\u0065\u0061\u0074\u006f\u0072\u003a\u0020\u0025\u0073\u0020<\u0025\u0073\u003e\u000a",_dg .CreatorName ,_dg .CreatorEmail );return _eaa ;};
2020-08-27 21:45:09 +00:00
// SetLicenseKey sets and validates the license key.
2020-10-12 14:17:59 +00:00
func SetLicenseKey (content string ,customerName string )error {_gfgb ,_aecf :=_ecc (content );if _aecf !=nil {_fd .Log .Error ("\u004c\u0069c\u0065\u006e\u0073\u0065\u0020\u0063\u006f\u0064\u0065\u0020\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0065\u0072\u0072\u006f\u0072: \u0025\u0076",_aecf );return _aecf ;};if _c .ToLower (_gfgb .CustomerName )!=_c .ToLower (customerName ){_fd .Log .Error ("L\u0069ce\u006es\u0065 \u0063\u006f\u0064\u0065\u0020i\u0073\u0073\u0075e\u0020\u002d\u0020\u0043\u0075s\u0074\u006f\u006de\u0072\u0020\u006e\u0061\u006d\u0065\u0020\u006d\u0069\u0073\u006da\u0074\u0063\u0068, e\u0078\u0070\u0065\u0063\u0074\u0065d\u0020\u0027\u0025\u0073\u0027\u002c\u0020\u0062\u0075\u0074\u0020\u0067o\u0074 \u0027\u0025\u0073\u0027",customerName ,_gfgb .CustomerName );return _g .Errorf ("\u0063\u0075\u0073\u0074\u006fm\u0065\u0072\u0020\u006e\u0061\u006d\u0065\u0020\u006d\u0069\u0073\u006d\u0061t\u0063\u0068\u002c\u0020\u0065\u0078\u0070\u0065\u0063\u0074\u0065\u0064\u0020\u0027\u0025\u0073\u0027\u002c\u0020\u0062\u0075\u0074\u0020\u0067\u006f\u0074\u0020\u0027\u0025\u0073'",customerName ,_gfgb .CustomerName );};_aecf =_gfgb .Validate ();if _aecf !=nil {_fd .Log .Error ("\u004c\u0069\u0063\u0065\u006e\u0073e\u0020\u0063\u006f\u0064\u0065\u0020\u0076\u0061\u006c\u0069\u0064\u0061\u0074i\u006f\u006e\u0020\u0065\u0072\u0072\u006fr\u003a\u0020\u0025\u0076",_aecf );return _aecf ;};_fdg =&_gfgb ;return nil ;};const (_be ="\u002d\u002d\u002d--\u0042\u0045\u0047\u0049\u004e\u0020\u0055\u004e\u0049D\u004fC\u0020L\u0049C\u0045\u004e\u0053\u0045\u0020\u004b\u0045\u0059\u002d\u002d\u002d\u002d\u002d";_ca ="\u002d\u002d\u002d\u002d\u002d\u0045\u004e\u0044\u0020\u0055\u004e\u0049\u0044\u004f\u0043 \u004cI\u0043\u0045\u004e\u0053\u0045\u0020\u004b\u0045\u0059\u002d\u002d\u002d\u002d\u002d";);type LicenseKey struct{LicenseId string `json:"license_id"`;CustomerId string `json:"customer_id"`;CustomerName string `json:"customer_name"`;Tier string `json:"tier"`;CreatedAt _fg .Time `json:"-"`;CreatedAtInt int64 `json:"created_at"`;ExpiresAt *_fg .Time `json:"-"`;ExpiresAtInt int64 `json:"expires_at"`;CreatedBy string `json:"created_by"`;CreatorName string `json:"creator_name"`;CreatorEmail string `json:"creator_email"`;UniPDF bool `json:"unipdf"`;UniOffice bool `json:"unioffice"`;Trial bool `json:"trial"`;};const _efa ="\u0055\u004e\u0049\u0050DF\u005f\u004c\u0049\u0043\u0045\u004e\u0053\u0045\u005f\u0050\u0041\u0054\u0048";func (_db *LicenseKey )getExpiryDateToCompare ()_fg .Time {if _db .Trial {return _fg .Now ().UTC ();};return _fd .ReleasedAt ;};func (_aec *LicenseKey )Validate ()error {if len (_aec .LicenseId )< 10{return _g .Errorf ("i\u006e\u0076\u0061\u006c\u0069\u0064 \u006c\u0069\u0063\u0065\u006e\u0073\u0065\u003a\u0020L\u0069\u0063\u0065n\u0073e\u0020\u0049\u0064");};if len (_aec .CustomerId )< 10{return _g .Errorf ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006c\u0069\u0063\u0065\u006e\u0073\u0065:\u0020C\u0075\u0073\u0074\u006f\u006d\u0065\u0072 \u0049\u0064");};if len (_aec .CustomerName )< 1{return _g .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0069c\u0065\u006e\u0073\u0065\u003a\u0020\u0043u\u0073\u0074\u006f\u006d\u0065\u0072\u0020\u004e\u0061\u006d\u0065");};if _bd .After (_aec .CreatedAt ){return _g .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0069\u0063\u0065\u006e\u0073\u0065\u003a\u0020\u0043\u0072\u0065\u0061\u0074\u0065\u0064 \u0041\u0074\u0020\u0069\u0073 \u0069\u006ev\u0061\u006c\u0069\u0064");};if _aec .ExpiresAt ==nil {_defg :=_aec .CreatedAt .AddDate (1,0,0);if _ebc .After (_defg ){_defg =_ebc ;};_aec .ExpiresAt =&_defg ;};if _aec .CreatedAt .After (*_aec .ExpiresAt ){return _g .Errorf ("i\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0069\u0063\u0065\u006e\u0073\u0065\u003a\u0020\u0043\u0072\u0065\u0061\u0074\u0065\u0064\u0020\u0041\u0074 \u0063a\u006e\u006e\u006f\u0074 \u0062\u0065 \u0047\u0072\u0065\u0061\u0074\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0045\u0078\u0070\u0069\u0072\u0065\u0073\u0020\u0041\u0074");};if _aec .isExpired (){return