Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Apr 20, 2023
1 parent 2347614 commit 96c0ce9
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 54 deletions.
2 changes: 1 addition & 1 deletion pkg/lakego-pkg/go-cryptobin/cipher/cfb1.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func NewCFB1(block cipher.Block, iv []byte, decrypt bool) cipher.Stream {

x := &cfb1{
b: block,
out: make([]byte, blockSize),
in: make([]byte, blockSize),
out: make([]byte, blockSize),
decrypt: decrypt,
}
copy(x.in, iv)
Expand Down
78 changes: 51 additions & 27 deletions pkg/lakego-pkg/go-cryptobin/cipher/cfb64.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,78 @@ package cipher

import (
"crypto/cipher"

"github.com/deatil/go-cryptobin/tool/alias"
)

type cfb64 struct {
encrypt bool
iv []byte
block cipher.Block
blockSize int
out []byte
b cipher.Block
in []byte
out []byte
decrypt bool
}

func (c *cfb64) XORKeyStream(dst, src []byte) {
for i := range src {
if len(c.out) == 0 {
c.block.Encrypt(c.out, c.iv)
// 每个块都进行异或
func (x *cfb64) XORKeyStream(dst, src []byte) {
if len(dst) < len(src) {
panic("cipher/cfb64: output smaller than input")
}

if alias.InexactOverlap(dst[:len(src)], src) {
panic("cipher/cfb64: invalid buffer overlap")
}

bs := 8
for i := 0; i < len(src); i += bs {
x.b.Encrypt(x.out, x.in)

end := i + bs
if end > len(src) {
end = len(src)
}

b := src[i]
if c.encrypt {
b ^= c.out[0]
xorBytes := make([]byte, 0)
srcBytes := make([]byte, 0)

for j := i; j < end; j++ {
xorBytes = append(xorBytes, src[j] ^ x.out[j-i])
srcBytes = append(srcBytes, src[j])
}

startIn := end - i
copy(x.in, x.in[startIn:])

if x.decrypt {
copy(x.in[startIn:], srcBytes)
} else {
c.out[0] ^= src[i]
b = c.out[0]
copy(x.in[startIn:], xorBytes)
}

copy(c.out, c.out[1:])
c.iv[c.blockSize-1] = b
dst[i] = b
copy(dst[i:end], xorBytes)
}
}

func NewCFB64(block cipher.Block, iv []byte, encrypt bool) cipher.Stream {
if len(iv) != block.BlockSize() {
func NewCFB64(block cipher.Block, iv []byte, decrypt bool) cipher.Stream {
blockSize := block.BlockSize()
if len(iv) != blockSize {
panic("cipher/cfb64: iv length must equal block size")
}

return &cfb64{
encrypt: encrypt,
iv: iv,
block: block,
blockSize: block.BlockSize(),
out: make([]byte, block.BlockSize()),
x := &cfb64{
b: block,
in: make([]byte, blockSize),
out: make([]byte, blockSize),
decrypt: decrypt,
}
copy(x.in, iv)

return x
}

func NewCFB64Encrypter(block cipher.Block, iv []byte) cipher.Stream {
return NewCFB64(block, iv, true)
return NewCFB64(block, iv, false)
}

func NewCFB64Decrypter(block cipher.Block, iv []byte) cipher.Stream {
return NewCFB64(block, iv, false)
return NewCFB64(block, iv, true)
}
1 change: 1 addition & 0 deletions pkg/lakego-pkg/go-cryptobin/cipher/cfb8.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (x *cfb8) XORKeyStream(dst, src []byte) {

for i := range src {
x.b.Encrypt(x.out, x.in)

copy(x.in[:x.blockSize-1], x.in[1:])
if x.decrypt {
x.in[x.blockSize-1] = src[i]
Expand Down
4 changes: 2 additions & 2 deletions pkg/lakego-pkg/lakego-doak/lakego/http/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"

"github.com/deatil/lakego-doak/lakego/router"
viewFinder "github.com/deatil/lakego-doak/lakego/view/finder"
view_finder "github.com/deatil/lakego-doak/lakego/view/finder"
)

// 使用
Expand Down Expand Up @@ -91,7 +91,7 @@ func (this *Response) ReturnJsonFromString(jsonStr string) {
func (this *Response) Fetch(template string, obj any) {
hintPathDelimiter := "::"
if strings.Contains(template, hintPathDelimiter) {
template = viewFinder.Instance().Find(template)
template = view_finder.Finder.Find(template)
}

this.ctx.HTML(this.httpCode, template, obj)
Expand Down
26 changes: 14 additions & 12 deletions pkg/lakego-pkg/lakego-doak/lakego/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package provider

import (
"path/filepath"

"github.com/deatil/lakego-filesystem/filesystem"

"github.com/deatil/lakego-doak/lakego/router"
"github.com/deatil/lakego-doak/lakego/publish"
"github.com/deatil/lakego-doak/lakego/command"
"github.com/deatil/lakego-doak/lakego/facade/config"
"github.com/deatil/lakego-doak/lakego/config/adapter"
pathTool "github.com/deatil/lakego-doak/lakego/path"
viewFunc "github.com/deatil/lakego-doak/lakego/view/funcs"
viewFinder "github.com/deatil/lakego-doak/lakego/view/finder"
appInterface "github.com/deatil/lakego-doak/lakego/app/interfaces"
path_tool "github.com/deatil/lakego-doak/lakego/path"
iapp "github.com/deatil/lakego-doak/lakego/app/interfaces"
view_func "github.com/deatil/lakego-doak/lakego/view/funcs"
view_finder "github.com/deatil/lakego-doak/lakego/view/finder"
)

/**
Expand All @@ -22,7 +24,7 @@ import (
*/
type ServiceProvider struct {
// 启动 app
App appInterface.App
App iapp.App

// 路由
Route *router.Engine
Expand All @@ -36,11 +38,11 @@ type ServiceProvider struct {

// 设置
func (this *ServiceProvider) WithApp(app any) {
this.App = app.(appInterface.App)
this.App = app.(iapp.App)
}

// 获取
func (this *ServiceProvider) GetApp() appInterface.App {
func (this *ServiceProvider) GetApp() iapp.App {
return this.App
}

Expand Down Expand Up @@ -132,7 +134,7 @@ func (this *ServiceProvider) CallBootedCallback() {
// 配置信息
func (this *ServiceProvider) MergeConfigFrom(path string, key string) {
// 格式化路径
path = pathTool.FormatPath(path)
path = path_tool.FormatPath(path)

newPath, err := filepath.Abs(path)
if err == nil {
Expand All @@ -142,12 +144,12 @@ func (this *ServiceProvider) MergeConfigFrom(path string, key string) {

// 注册视图
func (this *ServiceProvider) LoadViewsFrom(path string, namespace string) {
viewFinder := viewFinder.Instance()
viewFinder := view_finder.Finder

paths := config.New("view").GetStringSlice("paths")
if len(paths) > 0 {
for _, viewPath := range paths {
appPath := pathTool.FormatPath(viewPath) + "/pkg/" + namespace
appPath := path_tool.FormatPath(viewPath) + "/pkg/" + namespace

if filesystem.New().Exists(appPath) {
viewFinder.AddNamespace(namespace, []string{appPath})
Expand All @@ -156,14 +158,14 @@ func (this *ServiceProvider) LoadViewsFrom(path string, namespace string) {
}

// 格式化路径
path = pathTool.FormatPath(path)
path = path_tool.FormatPath(path)

viewFinder.AddNamespace(namespace, []string{path})
}

// 添加视图用方法
func (this *ServiceProvider) AddViewFunc(name string, fn any) {
viewFunc.AddFunc(name, fn)
view_func.AddFunc(name, fn)
}

// 推送
Expand Down
14 changes: 2 additions & 12 deletions pkg/lakego-pkg/lakego-doak/lakego/view/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@ package finder

import (
"os"
"sync"
"strings"
"path"
"path/filepath"
)

var instance *ViewFinder
var once sync.Once

// 单例
func Instance() *ViewFinder {
once.Do(func() {
instance = New()
})

return instance
}
// 默认
var Finder = New()

// 构造函数
func New() *ViewFinder {
Expand Down

0 comments on commit 96c0ce9

Please sign in to comment.