當前位置: 首頁>>代碼示例>>Golang>>正文


Golang utils.B58encode函數代碼示例

本文整理匯總了Golang中github.com/repbin/repbin/utils.B58encode函數的典型用法代碼示例。如果您正苦於以下問題:Golang B58encode函數的具體用法?Golang B58encode怎麽用?Golang B58encode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了B58encode函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Encode

// Encode an expireStruct
func (es ExpireStruct) Encode() ExpireStructEncoded {
	out := make([]byte, 0, ExpireStructSize)
	out = append(out, []byte(strconv.FormatUint(es.ExpireTime, 10)+" ")...)
	out = append(out, []byte(utils.B58encode(es.MessageID[:])+" ")...)
	out = append(out, []byte(utils.B58encode(es.SignerPubKey[:])+" ")...)
	return out[:len(out)]
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:8,代碼來源:expirestruct.go

示例2: ServeID

// ServeID returns server information.
func (ms MessageServer) ServeID(w http.ResponseWriter, r *http.Request) {
	ms.RandomSleep()
	now := CurrentTime() + ms.TimeSkew
	privK := [32]byte(*ms.authPrivKey)
	_, pubkey, challenge := keyauth.GenTempKeyTime(uint64(now), &privK)
	info := &ServerInfo{
		Time:            now,
		AuthPubKey:      utils.B58encode(pubkey[:]),
		AuthChallenge:   utils.B58encode(challenge[:]),
		MaxPostSize:     int64(messagestore.MaxMessageSize),
		MinPostSize:     ms.InfoStruct.MinPostSize,
		MinHashCashBits: ms.InfoStruct.MinHashCashBits,
	}
	if ms.EnablePeerHandler {
		info.Peers = ms.getPeerURLs()
	}
	ms.RandomSleep()
	w.Header().Set("Content-Type", "text/json")
	b, err := json.Marshal(info)
	if err != nil {
		log.Debugf("Info: %s\n", err)
	}
	w.Write(b)
	w.Write([]byte("\n"))
	return
}
開發者ID:RoPe93,項目名稱:repbin,代碼行數:27,代碼來源:server.go

示例3: ExpireFromIndex

// ExpireFromIndex reads the expire index and expires messages as they are recorded
func (store Store) ExpireFromIndex() {
	// ExpireRun
	delMessages, err := store.db.SelectMessageExpire(CurrentTime())
	if err != nil {
		log.Errorf("ExpireFromIndex, SelectMessageExpire: %s\n", err)
		return
	}
	for _, msg := range delMessages {
		err := store.db.DeleteBlob(&msg.MessageID)
		if err != nil {
			log.Errorf("ExpireFromIndex, DeleteBlob: %s %s\n", err, utils.B58encode(msg.MessageID[:]))
			continue
		}
		err = store.db.DeleteMessageByID(&msg.MessageID)
		if err != nil {
			log.Errorf("ExpireFromIndex, DeleteMessageByID: %s %s\n", err, utils.B58encode(msg.MessageID[:]))
		}
	}
	_, _, err = store.db.ExpireSigners(MaxAgeSigners)
	if err != nil {
		log.Errorf("ExpireFromIndex, ExpireSigners: %s\n", err)
	}
	err = store.db.ExpireMessageCounter(MaxAgeRecipients)
	if err != nil {
		log.Errorf("ExpireFromIndex, ExpireMessageCounter: %s\n", err)
	}
	err = store.db.ForgetMessages(CurrentTime() - MaxAgeRecipients)
	if err != nil {
		log.Errorf("ExpireFromIndex, ForgetMessages: %s\n", err)
	}
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:32,代碼來源:expire.go

示例4: New

// New returns a MessageServer.
func New(driver, url, path string, pubKey, privKey []byte) (*MessageServer, error) {
	var err error
	ms := new(MessageServer)
	ms.DB = messagestore.New(driver, url, path, Workers)
	if err != nil {
		return nil, err
	}
	ms.path = path
	ms.PeerFile = path + "peers.config"
	ms.AddToPeer = DefaultAddToPeer
	ms.MaxTimeSkew = DefaultMaxTimeSkew
	ms.MinPostSize = MinPostSize
	ms.MaxPostSize = MaxPostSize
	ms.MinHashCashBits = MinHashCashBits
	ms.MaxSleep = DefaultMaxSleep
	ms.MaxIndexGlobal = DefaultIndexGlobal
	ms.MaxIndexKey = DefaultIndexKey
	ms.TimeGrace = DefaultTimeGrace
	ms.MaxAuthTokenAge = DefaultAuthTokenAge
	ms.NotifyDuration = DefaultNotifyDuration
	ms.FetchDuration = DefaultFetchDuration
	ms.FetchMax = DefaultFetchMax
	ms.ExpireDuration = DefaultExpireDuration
	ms.ExpireFSDuration = DefaultExpireFSDuration
	ms.StepLimit = DefaultStepLimit
	ms.ListenPort = DefaultListenPort
	ms.MinStoreTime = DefaultMinStoreTime
	ms.MaxStoreTime = DefaultMaxStoreTime
	ms.MaxAgeSigners = DefaultMaxAgeSigners
	ms.MaxAgeRecipients = DefaultMaxAgeRecipients
	messagestore.MaxAgeRecipients = DefaultMaxAgeRecipients
	messagestore.MaxAgeSigners = DefaultMaxAgeSigners
	ms.EnablePeerHandler = true

	ms.authPrivKey, err = message.GenLongTermKey(true, false)
	if err != nil {
		return nil, err
	}
	ms.AuthPubKey = message.GenPubKey(ms.authPrivKey)
	if pubKey != nil && privKey != nil {
		ms.TokenPubKey = new([ed25519.PublicKeySize]byte)
		ms.TokenPrivKey = new([ed25519.PrivateKeySize]byte)
		copy(ms.TokenPubKey[:], pubKey)
		copy(ms.TokenPrivKey[:], privKey)
	} else {
		ms.TokenPubKey, ms.TokenPrivKey, err = ed25519.GenerateKey(rand.Reader)
		log.Printf("Peer authentication public key: %s\n", utils.B58encode(ms.TokenPubKey[:]))
		log.Printf("Peer authentication private key: %s\n", utils.B58encode(ms.TokenPrivKey[:]))
		if err != nil {
			return nil, err
		}
	}
	ms.InfoStruct = new(ServerInfo)
	ms.InfoStruct.MinHashCashBits = ms.MinHashCashBits
	ms.InfoStruct.MinPostSize = ms.MinPostSize
	ms.InfoStruct.MaxPostSize = ms.MaxPostSize
	ms.InfoStruct.AuthPubKey = utils.B58encode(ms.AuthPubKey[:])
	return ms, nil
}
開發者ID:RoPe93,項目名稱:repbin,代碼行數:60,代碼來源:server.go

示例5: GetNotify

// GetNotify receives notifications.
func (ms MessageServer) GetNotify(w http.ResponseWriter, r *http.Request) {
	var proof [keyproof.ProofTokenSize]byte
	w.Header().Set("Content-Type", "text/plain; charset=us-ascii")
	getValues := r.URL.Query()
	if getValues != nil {
		if v, ok := getValues["auth"]; ok {
			if len(v[0]) > keyproof.ProofTokenMax {
				io.WriteString(w, "ERROR: Bad Param\n")
				return
			}
			auth := utils.B58decode(v[0])
			if auth == nil || len(auth) > keyproof.ProofTokenSize {
				io.WriteString(w, "ERROR: Bad Param\n")
				return
			}
			copy(proof[:], auth)
			ok, timeStamp, senderPubKey := keyproof.VerifyProofToken(&proof, ms.TokenPubKey)
			if !ok {
				io.WriteString(w, "ERROR: Authentication failure\n")
				if senderPubKey == nil {
					log.Errorf("VerifyProofToken failed: (proof) %s\n", utils.B58encode(proof[:]))
				} else {
					log.Errorf("VerifyProofToken failed: (pubkey) %s\n", utils.B58encode(senderPubKey[:]))
				}
				return
			}
			// verify that we know the peer
			url := ms.PeerURL(senderPubKey)
			if url == "" {
				io.WriteString(w, "ERROR: Bad peer\n")
				log.Errorf("Notify, bad peer: %s\n", utils.B58encode(senderPubKey[:]))
				return
			}
			now := CurrentTime()
			// Test too old, too young
			if enforceTimeOuts && (now > timeStamp+DefaultAuthTokenAge+ms.MaxTimeSkew || now < timeStamp-DefaultAuthTokenAge-ms.MaxTimeSkew) {
				io.WriteString(w, "ERROR: Authentication expired\n")
				log.Errorf("VerifyProofToken replay by %s\n", url)
				return
			}
			ok, signedToken := keyproof.CounterSignToken(&proof, ms.TokenPubKey, ms.TokenPrivKey)
			if !ok {
				io.WriteString(w, "ERROR: Authentication failure\n")
				return
			}
			ms.DB.UpdatePeerAuthToken(senderPubKey, signedToken)
			log.Debugf("Notified by %s\n", url)
			io.WriteString(w, "SUCCESS: Notified\n")
			return
		}
	}
	io.WriteString(w, "ERROR: Missing Param\n")
	return
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:55,代碼來源:notify.go

示例6: showConfig

// showConfig shows current (default) config
func showConfig() {
	if defaultSettings.PeeringPrivateKey == "" {
		pubkey, privkey, err := ed25519.GenerateKey(rand.Reader)
		if err == nil {
			defaultSettings.PeeringPrivateKey = utils.B58encode(privkey[:])
			defaultSettings.PeeringPublicKey = utils.B58encode(pubkey[:])
		}
	}
	config, _ := json.MarshalIndent(defaultSettings, "", "    ")
	fmt.Println(string(config))
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:12,代碼來源:config.go

示例7: Encode

// Encode a SignerStruct to human readable representation
func (ss SignerStruct) Encode() SignerStructEncoded {
	out := make([]byte, 0, SignerStructSize)
	out = append(out, []byte(utils.B58encode(ss.PublicKey[:])+" ")...)
	out = append(out, []byte(utils.B58encode(ss.Nonce[:])+" ")...)
	out = append(out, []byte(strconv.FormatUint(uint64(ss.Bits), 10)+" ")...)
	out = append(out, []byte(strconv.FormatUint(ss.MessagesPosted, 10)+" ")...)
	out = append(out, []byte(strconv.FormatUint(ss.MessagesRetained, 10)+" ")...)
	out = append(out, []byte(strconv.FormatUint(ss.MaxMessagesPosted, 10)+" ")...)
	out = append(out, []byte(strconv.FormatUint(ss.MaxMessagesRetained, 10)+" ")...)
	out = append(out, []byte(strconv.FormatUint(ss.ExpireTarget, 10)+" ")...)
	return out[:len(out)]
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:13,代碼來源:signerstruct.go

示例8: CmdGenKey

// CmdGenKey generates a long-term public key
func CmdGenKey() int {
	privkey, err := message.GenLongTermKey(OptionsVar.Hidden, OptionsVar.Sync)
	if err != nil {
		log.Errorf("Key generation error:%s\n", err)
		return 1
	}
	pubkey := message.GenPubKey(privkey)
	log.Dataf("STATUS (PrivateKey):\t%s\n", utils.B58encode(privkey[:]))
	// log.Dataf("STATUS (PublicKey):\t%s\n", utils.B58encode(pubkey[:]))
	log.Printf("PRIVATE key: %s\n\n", utils.B58encode(privkey[:]))
	// log.Printf("Public key: %s\n", utils.B58encode(pubkey[:]))
	_ = pubkey
	return 0
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:15,代碼來源:genkey.go

示例9: Encode

// Encode encodes a MessageStruct in human-readable format for storage
func (ms MessageStruct) Encode() MessageStructEncoded {
	out := make([]byte, 0, MessageStructSize)
	out = append(out, []byte(strconv.FormatUint(ms.Counter, 10)+" ")...)
	out = append(out, []byte(strconv.FormatUint(ms.PostTime, 10)+" ")...)
	out = append(out, []byte(strconv.FormatUint(ms.ExpireTime, 10)+" ")...)
	out = append(out, []byte(strconv.FormatUint(ms.ExpireRequest, 10)+" ")...)
	out = append(out, []byte(utils.B58encode(ms.MessageID[:])+" ")...)
	out = append(out, []byte(utils.B58encode(ms.ReceiverConstantPubKey[:])+" ")...)
	out = append(out, []byte(utils.B58encode(ms.SignerPub[:])+" ")...)
	out = append(out, []byte(strconv.FormatUint(ms.Distance, 10)+" ")...)
	out = append(out, []byte(BoolToString(ms.OneTime)+" ")...)
	out = append(out, []byte(BoolToString(ms.Sync)+" ")...)
	out = append(out, []byte(BoolToString(ms.Hidden))...)
	return out[:len(out)]
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:16,代碼來源:messagestruct.go

示例10: KeyCallBack

// KeyCallBack implements a callback function to request keys from file-descriptor
func KeyCallBack(keyMgtFd int) (*os.File, func(*message.Curve25519Key) *message.Curve25519Key) {
	knownKeys := make(map[message.Curve25519Key]message.Curve25519Key)
	fd := os.NewFile(uintptr(keyMgtFd), "fd/"+strconv.Itoa(keyMgtFd))
	return fd, func(pubkey *message.Curve25519Key) *message.Curve25519Key {
		// KeyCallBack func(*Curve25519Key) *Curve25519Key
		log.Sync()
		if v, ok := knownKeys[*pubkey]; ok { // Return from cache if we can
			return &v
		}
		b := make([]byte, 120)
		log.Dataf("STATUS (KeyMGTRequest):\t%s\n", utils.B58encode(pubkey[:]))
		log.Sync()
		n, _ := fd.Read(b)
		if n == 0 {
			log.Datas("STATUS (KeyMGT):\tREAD FAILURE\n")
			return nil
		}
		log.Datas("STATUS (KeyMGT):\tREAD DONE\n")
		k1, k2 := utils.ParseKeyPair(strings.Trim(string(b[:n]), " \t\r\n"))
		if k1 != nil {
			pub1 := message.GenPubKey(k1) // Add to cache
			knownKeys[*pub1] = *k1
		}
		if k2 != nil {
			pub2 := message.GenPubKey(k2) // Add to cache
			knownKeys[*pub2] = *k2
		}
		if v, ok := knownKeys[*pubkey]; ok { // Return from cache if we can
			return &v
		}
		return nil
	}
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:34,代碼來源:keymgt.go

示例11: GetPeerStat

// GetPeerStat returns the last entry of peer statistics for pubkey
func (store Store) GetPeerStat(pubkey *[ed25519.PublicKeySize]byte) *structs.PeerStruct {
	st, err := store.db.SelectPeer(pubkey)
	if err != nil {
		log.Errorf("GetPeerStat: %s, %s\n", err, utils.B58encode(pubkey[:]))
		return nil
	}
	return st
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:9,代碼來源:peers.go

示例12: GetSpecificAuth

// GetSpecificAuth fetches a message from a specific server using authentication
func (proto *Proto) GetSpecificAuth(server, auth string, messageID []byte) ([]byte, error) {
	messageIDenc := utils.B58encode(messageID)
	body, err := socks.Proxy(proto.SocksServer).LimitGet(constructURL(server, "/fetch", "?messageid=", messageIDenc, "&auth=", auth), 512000)
	if err != nil {
		return nil, err
	}
	return parseError(body)
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:9,代碼來源:getpost.go

示例13: Encode

// Encode peerstruct into human readable form
func (ps PeerStruct) Encode() PeerStructEncoded {
	out := make([]byte, 0, PeerStructSize)
	out = append(out, []byte(utils.B58encode(ps.AuthToken[:])+" ")...)
	out = append(out, []byte(strconv.FormatUint(ps.LastNotifySend, 10)+" ")...)
	out = append(out, []byte(strconv.FormatUint(ps.LastNotifyFrom, 10)+" ")...)
	out = append(out, []byte(strconv.FormatUint(ps.LastFetch, 10)+" ")...)
	out = append(out, []byte(strconv.FormatUint(ps.ErrorCount, 10)+" ")...)
	out = append(out, []byte(strconv.FormatUint(ps.LastPosition, 10)+" ")...)
	return out[:len(out)]
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:11,代碼來源:peerstruct.go

示例14: GetGlobalIndex

// GetGlobalIndex returns the global index.
func (ms MessageServer) GetGlobalIndex(w http.ResponseWriter, r *http.Request) {
	var pubKey *message.Curve25519Key
	start := int64(0)
	count := int64(10)
	w.Header().Set("Content-Type", "text/plain; charset=us-ascii")
	getValues := r.URL.Query()
	if getValues != nil {
		if v, ok := getValues["start"]; ok {
			t, err := strconv.Atoi(v[0])
			if err == nil {
				start = int64(t)
			}
		}
		if v, ok := getValues["count"]; ok {
			t, err := strconv.Atoi(v[0])
			if err == nil {
				count = int64(t)
				if count > ms.MaxIndexGlobal {
					count = ms.MaxIndexGlobal
				}
			}
		}
		if v, ok := getValues["auth"]; ok {
			err := ms.AuthenticatePeer(v[0])
			if err != nil {
				io.WriteString(w, fmt.Sprintf("Error: %s", err))
				return
			}
		} else {
			io.WriteString(w, "ERROR: Missing param\n")
			return
		}
	} else {
		io.WriteString(w, "ERROR: Missing param\n")
		return
	}
	messages, found, err := ms.DB.GetGlobalIndex(start, count)
	if err != nil && err != ErrNoMore {
		log.Debugf("List:GetIndex: %s\n", err)
		log.Debugf("List:GetIndex: Key %s\n", utils.B58encode(pubKey[:]))
		io.WriteString(w, "ERROR: List failed\n")
		return
	}
	io.WriteString(w, "SUCCESS: Data follows\n")
	for _, msg := range messages {
		io.WriteString(w, "IDX: "+strings.Trim(string(msg), " \t\n\r")+"\n")
	}
	if int64(found) < count {
		io.WriteString(w, "CMD: Exceeded\n")
	} else {
		io.WriteString(w, "CMD: Continue\n")
	}
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:54,代碼來源:getglobalindex.go

示例15: Auth

// Auth creates an authentication for server and privKey
func (proto *Proto) Auth(server string, privKey []byte) (string, error) {
	var challenge [keyauth.ChallengeSize]byte
	var secret [keyauth.PrivateKeySize]byte
	info, err := proto.ID(server)
	if err != nil {
		return "", err
	}
	challengeS := utils.B58decode(info.AuthChallenge)
	copy(challenge[:], challengeS)
	copy(secret[:], privKey[:])
	answer := keyauth.Answer(&challenge, &secret)
	return utils.B58encode(answer[:]), nil
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:14,代碼來源:getpost.go


注:本文中的github.com/repbin/repbin/utils.B58encode函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。