• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang encrypter.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/intelsdi-x/snap/control/plugin/encrypter.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: startHTTPJSONRPC

func startHTTPJSONRPC() (string, *mockSessionStatePluginProxy) {
	encr := encrypter.New(&key.PublicKey, nil)
	encr.Key = symkey
	ee := encoding.NewJsonEncoder()
	ee.SetEncrypter(encr)
	mockProxy := &mockProxy{e: ee}
	mockCollectorProxy := &mockCollectorProxy{e: ee}
	rpc.RegisterName("Collector", mockCollectorProxy)
	rpc.RegisterName("Processor", mockProxy)
	rpc.RegisterName("Publisher", mockProxy)
	session := &mockSessionStatePluginProxy{e: ee}
	rpc.RegisterName("SessionState", session)
	rpc.HandleHTTP()

	l, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		panic(err)
	}
	go func() {
		http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
			defer req.Body.Close()
			w.Header().Set("Content-Type", "application/json")
			res := plugin.NewRPCRequest(req.Body).Call()
			io.Copy(w, res)
		})
		http.Serve(l, nil)
	}()

	return l.Addr().String(), session
}
开发者ID:jeffweiss,项目名称:snap,代码行数:30,代码来源:httpjsonrpc_test.go


示例2: newNativeClient

func newNativeClient(address string, timeout time.Duration, t plugin.PluginType, pub *rsa.PublicKey, secure bool) (*PluginNativeClient, error) {
	// Attempt to dial address error on timeout or problem
	conn, err := net.DialTimeout("tcp", address, timeout)
	// Return nil RPCClient and err if encoutered
	if err != nil {
		return nil, err
	}
	r := rpc.NewClient(conn)
	p := &PluginNativeClient{
		connection: r,
		pluginType: t,
		timeout:    timeout,
	}

	p.encoder = encoding.NewGobEncoder()

	if secure {
		key, err := encrypter.GenerateKey()
		if err != nil {
			return nil, err
		}
		encrypter := encrypter.New(pub, nil)
		encrypter.Key = key
		p.encrypter = encrypter
		p.encoder.SetEncrypter(encrypter)
	}

	return p, nil
}
开发者ID:IRCody,项目名称:snap,代码行数:29,代码来源:native.go


示例3: NewPublisherHttpJSONRPCClient

func NewPublisherHttpJSONRPCClient(u string, timeout time.Duration, pub *rsa.PublicKey, secure bool) (PluginPublisherClient, error) {
	hjr := &httpJSONRPCClient{
		url:        u,
		timeout:    timeout,
		pluginType: plugin.PublisherPluginType,
		encoder:    encoding.NewJsonEncoder(),
	}
	if secure {
		key, err := encrypter.GenerateKey()
		if err != nil {
			return nil, err
		}
		e := encrypter.New(pub, nil)
		e.Key = key
		hjr.encoder.SetEncrypter(e)
		hjr.encrypter = e
	}
	return hjr, nil
}
开发者ID:jcooklin,项目名称:snap,代码行数:19,代码来源:httpjsonrpc.go


示例4: NewProcessorGrpcClient

// NewProcessorGrpcClient returns a processor gRPC Client.
func NewProcessorGrpcClient(address string, timeout time.Duration, pub *rsa.PublicKey, secure bool) (PluginProcessorClient, error) {
	address, port, err := parseAddress(address)
	if err != nil {
		return nil, err
	}
	p, err := newGrpcClient(address, int(port), timeout, plugin.ProcessorPluginType)
	if err != nil {
		return nil, err
	}
	if secure {
		key, err := encrypter.GenerateKey()
		if err != nil {
			return nil, err
		}
		encrypter := encrypter.New(pub, nil)
		encrypter.Key = key
		p.encrypter = encrypter
	}

	return p, nil
}
开发者ID:IRCody,项目名称:snap,代码行数:22,代码来源:grpc.go


示例5: NewSessionState

// NewSessionState takes the plugin args and returns a SessionState
// returns State or error and returnCode:
// 0 - ok
// 2 - error when unmarshaling pluginArgs
// 3 - cannot open error files
func NewSessionState(pluginArgsMsg string, plugin Plugin, meta *PluginMeta) (*SessionState, error, int) {
	pluginArg := &Arg{}
	err := json.Unmarshal([]byte(pluginArgsMsg), pluginArg)
	if err != nil {
		return nil, err, 2
	}

	// If no port was provided we let the OS select a port for us.
	// This is safe as address is returned in the Response and keep
	// alive prevents unattended plugins.
	if pluginArg.listenPort == "" {
		pluginArg.listenPort = "0"
	}

	// If no PingTimeoutDuration was provided we need to set it
	if pluginArg.PingTimeoutDuration == 0 {
		pluginArg.PingTimeoutDuration = PingTimeoutDurationDefault
	}

	// Generate random token for this session
	rb := make([]byte, 32)
	rand.Read(rb)
	rs := base64.URLEncoding.EncodeToString(rb)

	logger := &log.Logger{
		Out:       os.Stderr,
		Formatter: &simpleFormatter{},
		Hooks:     make(log.LevelHooks),
		Level:     pluginArg.LogLevel,
	}

	var enc encoding.Encoder
	switch meta.RPCType {
	case JSONRPC:
		enc = encoding.NewJsonEncoder()
	case NativeRPC:
		enc = encoding.NewGobEncoder()
	case GRPC:
		enc = encoding.NewGobEncoder()
		//TODO(CDR): re-think once content-types is settled
	}
	ss := &SessionState{
		Arg:     pluginArg,
		Encoder: enc,

		plugin:   plugin,
		token:    rs,
		killChan: make(chan int),
		logger:   logger,
	}

	if !meta.Unsecure {
		key, err := rsa.GenerateKey(rand.Reader, 2048)
		if err != nil {
			return nil, err, 2
		}
		encrypt := encrypter.New(nil, key)
		enc.SetEncrypter(encrypt)
		ss.Encrypter = encrypt
		ss.privateKey = key
	}
	return ss, nil, 0
}
开发者ID:IRCody,项目名称:snap,代码行数:68,代码来源:session.go


示例6: NewSessionState

// NewSessionState takes the plugin args and returns a SessionState
// returns State or error and returnCode:
// 0 - ok
// 2 - error when unmarshaling pluginArgs
// 3 - cannot open error files
func NewSessionState(pluginArgsMsg string, plugin Plugin, meta *PluginMeta) (*SessionState, error, int) {
	pluginArg := &Arg{}
	err := json.Unmarshal([]byte(pluginArgsMsg), pluginArg)
	if err != nil {
		return nil, err, 2
	}

	// If no port was provided we let the OS select a port for us.
	// This is safe as address is returned in the Response and keep
	// alive prevents unattended plugins.
	if pluginArg.listenPort == "" {
		pluginArg.listenPort = "0"
	}

	// If no PingTimeoutDuration was provided we need to set it
	if pluginArg.PingTimeoutDuration == 0 {
		pluginArg.PingTimeoutDuration = PingTimeoutDurationDefault
	}

	// Generate random token for this session
	rb := make([]byte, 32)
	rand.Read(rb)
	rs := base64.URLEncoding.EncodeToString(rb)

	// Initialize a logger based on PluginLogPath
	truncOrAppend := os.O_TRUNC // truncate log file explicitly given by user
	// Empty or /tmp means use default tmp log (needs to be removed post-aAtruncOrAppendpha)
	if pluginArg.PluginLogPath == "" || pluginArg.PluginLogPath == "/tmp" {
		if runtime.GOOS == "windows" {
			pluginArg.PluginLogPath = `c:\TEMP\snap_plugin.log`
		} else {
			pluginArg.PluginLogPath = "/tmp/snap_plugin.log"
		}
		truncOrAppend = os.O_APPEND
	}
	lf, err := os.OpenFile(pluginArg.PluginLogPath, os.O_WRONLY|os.O_CREATE|truncOrAppend, 0666)
	if err != nil {
		return nil, errors.New(fmt.Sprintf("error opening log file: %v", err)), 3
	}
	logger := log.New(lf, ">>>", log.Ldate|log.Ltime)

	var enc encoding.Encoder
	switch meta.RPCType {
	case JSONRPC:
		enc = encoding.NewJsonEncoder()
	case NativeRPC:
		enc = encoding.NewGobEncoder()
	}
	ss := &SessionState{
		Arg:     pluginArg,
		Encoder: enc,

		plugin:   plugin,
		token:    rs,
		killChan: make(chan int),
		logger:   logger,
	}

	if !meta.Unsecure {
		key, err := rsa.GenerateKey(rand.Reader, 2048)
		if err != nil {
			return nil, err, 2
		}
		encrypt := encrypter.New(nil, key)
		enc.SetEncrypter(encrypt)
		ss.Encrypter = encrypt
		ss.privateKey = key
	}
	return ss, nil, 0
}
开发者ID:mtanda,项目名称:snap,代码行数:75,代码来源:session.go



注:本文中的github.com/intelsdi-x/snap/control/plugin/encrypter.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang strategy.Pool类代码示例发布时间:2022-05-23
下一篇:
Golang cpolicy.NewStringRule函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap