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


Golang utils.B58decode函數代碼示例

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


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

示例1: main

// This is just for testing
func main() {
	var pubKey, privKey []byte
	pubKey, privKey = nil, nil

	if defaultSettings.StoragePath == "" {
		fmt.Println("Error: Storage path not configured")
		os.Exit(1)
	}

	if defaultSettings.PeeringPublicKey != "" && defaultSettings.PeeringPrivateKey != "" {
		pubKey = utils.B58decode(defaultSettings.PeeringPublicKey)
		privKey = utils.B58decode(defaultSettings.PeeringPrivateKey)
	}

	runtime.GOMAXPROCS(runtime.NumCPU() - 1)

	ms, err := handlers.New(defaultSettings.StoragePath, pubKey, privKey)
	if err != nil {
		fmt.Printf("Error: %s\n", err)
		os.Exit(1)
	}
	applyConfig(ms)
	ms.Stat = *stat
	if *start {
		ms.RunServer()
	} else {
		fmt.Println("Server not started. Enable with --start")
		os.Exit(1)
	}
	os.Exit(0)
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:32,代碼來源:repserver.go

示例2: TestIDSpecific

func TestIDSpecific(t *testing.T) {
	var privKey, pubKey message.Curve25519Key
	var pk []byte
	//pk = utils.B58decode("i2BNvH9h85NWDxDZj2VpF8nuvUpSQy57ud3hrzo3gxM")
	pk = utils.B58decode("ATWZibbLy5CFE5atp98hxFRAvFcjN7kNn16WtP43tnJ6")
	pk = utils.B58decode("FpYAGsxrpmgh8CUJkFEnz1CCY9ZUhbVxtTekfkFyWxdQ")
	copy(privKey[:], pk[:])
	pubKey = *message.GenPubKey(&privKey)
	// long test with local server
	if testing.Short() {
		t.Skip("test skipped in -short run")
	}
	proto := New("", "http://127.0.0.1:8080")
	info, err := proto.Auth("http://127.0.0.1:8080", privKey[:])
	if err != nil {
		t.Fatalf("ID: %s", err)
	}
	_ = info
	msgs, more, err := proto.ListSpecific("http://127.0.0.1:8080", pubKey[:], privKey[:], 0, 10)
	if err != nil {
		t.Fatalf("ListSpecific: %s", err)
	}
	// fmt.Printf("%+v\n", msgs)
	_, _ = msgs, more
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:25,代碼來源:getpost_test.go

示例3: SignerStructDecode

// SignerStructDecode decodes an encoded signerstruct
func SignerStructDecode(d SignerStructEncoded) *SignerStruct {
	if len(d) < SignerStructMin {
		return nil
	}
	fields := bytes.Fields(d)
	if len(fields) != 8 {
		return nil
	}
	cur := 0
	ss := new(SignerStruct)
	t := utils.B58decode(string(fields[cur]))
	copy(ss.PublicKey[:], t)
	cur++
	t = utils.B58decode(string(fields[cur]))
	copy(ss.Nonce[:], t)
	cur++
	tb, _ := strconv.ParseUint(string(fields[cur]), 10, 64)
	ss.Bits = byte(tb)
	cur++
	ss.MessagesPosted, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	ss.MessagesRetained, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	ss.MaxMessagesPosted, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	ss.MaxMessagesRetained, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	ss.ExpireTarget, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	return ss
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:31,代碼來源:signerstruct.go

示例4: ExpireStructDecode

// ExpireStructDecode decodes an encoded ExpireStruct
func ExpireStructDecode(d ExpireStructEncoded) *ExpireStruct {
	if len(d) < ExpireStructMin {
		return nil
	}
	fields := bytes.Fields(d)
	if len(fields) < 3 {
		return nil
	}
	cur := 0
	es := new(ExpireStruct)
	es.ExpireTime, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	t := utils.B58decode(string(fields[cur]))
	copy(es.MessageID[:], t)
	cur++
	t = utils.B58decode(string(fields[cur]))
	copy(es.SignerPubKey[:], t)
	return es
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:20,代碼來源:expirestruct.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: Delete

// Delete implements the delete call for messages.
func (ms MessageServer) Delete(w http.ResponseWriter, r *http.Request) {
	var messageID *[message.MessageIDSize]byte
	var privateKey *message.Curve25519Key
	for i := 0; i < 4; i++ {
		ms.RandomSleep() // Let's not give instant gratification here
	}
	w.Header().Set("Content-Type", "text/plain; charset=us-ascii")
	getValues := r.URL.Query()
	if getValues != nil {
		if v, ok := getValues["messageid"]; ok {
			t := utils.B58decode(v[0])
			if len(t) < message.MessageIDSize || len(t) > message.MessageIDSize {
				io.WriteString(w, "ERROR: Bad parameter\n")
				return
			}
			messageID = new([message.MessageIDSize]byte)
			copy(messageID[:], t)
		}
		if v, ok := getValues["privkey"]; ok {
			t := utils.B58decode(v[0])
			if len(t) < message.Curve25519KeySize || len(t) > message.Curve25519KeySize {
				io.WriteString(w, "ERROR: Bad parameter\n")
				return
			}
			privateKey = new(message.Curve25519Key)
			copy(privateKey[:], t)
		}
		if privateKey != nil && messageID != nil {
			publicKey := message.GenPubKey(privateKey)
			err := ms.DB.PreExpire(messageID, publicKey)
			if err == nil {
				log.Errorf("Message censored: %x, asshole.\n", *messageID)
				io.WriteString(w, "SUCCESS: If you want to call it that\n")
				return
			}
			log.Errorf("Message censoring failed! %s\n", err)
		}
	}
	io.WriteString(w, "ERROR: Missing parameters\n")
	return
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:42,代碼來源:delete.go

示例7: cmdlineURLparse

// cmdlineURLparse parses the commandline into server, messageID and key
func cmdlineURLparse(args ...string) (string, []byte, string) {
	// server,messageID,key = server/messageID_key | server/messageID | messageID_key | messageID key | messageID
	var server, messageID, key string
	if len(args) == 2 { // messageid key
		return "", utils.B58decode(args[0]), args[1]
	}
	fsplit := strings.SplitN(args[0], "_", 2)
	if len(fsplit) == 2 {
		// last is key
		key = fsplit[1]
	}
	ssep := strings.LastIndex(fsplit[0], "/")
	if ssep == -1 {
		// No server data contained
		messageID = fsplit[0]
	} else {
		messageID = fsplit[0][ssep+1:] // last part is messageID
		server = fsplit[0][:ssep]      // first part is server
	}
	return server, utils.B58decode(messageID), key
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:22,代碼來源:utils.go

示例8: 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

示例9: LoadPeers

// LoadPeers from file.
func (ms MessageServer) LoadPeers() {
	var prePeerlist PeerListEncoded
	var myPeerURLs []string
	myPeers := make(PeerList)
	peersEncoded, err := ioutil.ReadFile(ms.PeerFile)
	if err != nil {
		example := make(PeerListEncoded, 1)
		example[0].PubKey = "Example ed25519 public key encoded in base58"
		example[0].URL = exampleURL
		dat, _ := json.MarshalIndent(example, "", "    ")
		_ = dat
		err := ioutil.WriteFile(ms.PeerFile, dat, 0600)
		if err != nil {
			log.Errorf("Could not write peerfile: %s\n", err)
			return
		}
		log.Debugs("Example peerfile written\n")
		return
	}
	err = json.Unmarshal(peersEncoded, &prePeerlist)
	if err != nil {
		log.Errorf("Could not read peerfile: %s\n", err)
		return
	}
	if ms.AddToPeer && !ms.HubOnly {
		myPeerURLs = append(myPeerURLs, ms.URL)
	}
	for _, p := range prePeerlist {
		if p.URL != exampleURL {
			var tkey [ed25519.PublicKeySize]byte
			t := utils.B58decode(p.PubKey)
			copy(tkey[:], t)
			if *ms.TokenPubKey != tkey || debug {
				myPeers[tkey] = Peer{
					URL:    p.URL,
					PubKey: tkey,
				}
				if !p.IsHub {
					myPeerURLs = append(myPeerURLs, p.URL)
				}
				// Create Peer Index File
				ms.DB.TouchPeer(&tkey)
			}
		}
	}
	defer ms.setPeerURLs(myPeerURLs)
	systemPeersMutex.Lock()
	defer systemPeersMutex.Unlock()
	systemPeers = myPeers
	log.Debugs("Peers loaded\n")
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:52,代碼來源:notifybackend.go

示例10: Fetch

// Fetch returns a single message.
func (ms MessageServer) Fetch(w http.ResponseWriter, r *http.Request) {
	var messageID *[message.MessageIDSize]byte
	w.Header().Set("Content-Type", "text/plain; charset=us-ascii")
	getValues := r.URL.Query()
	if getValues != nil {
		if v, ok := getValues["messageid"]; ok {
			t := utils.B58decode(v[0])
			if len(t) < message.MessageIDSize || len(t) > message.MessageIDSize {
				io.WriteString(w, "ERROR: Bad parameter\n")
				return
			}
			messageID = new([message.MessageIDSize]byte)
			copy(messageID[:], t)
		}
		if ms.HubOnly {
			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
			}
		}
	}
	if messageID == nil {
		io.WriteString(w, "ERROR: Missing parameter\n")
		return
	}
	data, err := ms.DB.Fetch(messageID)
	if err != nil {
		log.Debugf("Fetch: %s\n", err)
		io.WriteString(w, "ERROR: No data")
		return
	}
	io.WriteString(w, "SUCCESS: Data follows\n")
	_, err = w.Write(data)
	if err != nil {
		log.Debugf("Write: %s\n", err)
		return
	}
	log.Debugs("Fetch OK\n")
	if ms.Stat {
		stat.Input <- stat.Fetch
	}
	return
}
開發者ID:mewbak,項目名稱:repbin,代碼行數:50,代碼來源:fetch.go

示例11: MessageStructDecode

// MessageStructDecode decodes bytes to MessageStruct
func MessageStructDecode(d MessageStructEncoded) *MessageStruct {
	fields := bytes.Fields(d)
	l := len(fields)
	if l < 10 || l > 11 || len(d) < MessageStructMin { // with or without counter
		return nil
	}
	cur := 0
	ms := new(MessageStruct)
	if l == 11 { // with counter\
		ms.Counter, _ = strconv.ParseUint(string(fields[0]), 10, 64)
		cur++
	}
	ms.PostTime, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	ms.ExpireTime, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	ms.ExpireRequest, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	t := utils.B58decode(string(fields[cur]))
	copy(ms.MessageID[:], t)
	cur++
	t = utils.B58decode(string(fields[cur]))
	copy(ms.ReceiverConstantPubKey[:], t)
	cur++
	t = utils.B58decode(string(fields[cur]))
	copy(ms.SignerPub[:], t)
	cur++
	ms.Distance, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	ms.OneTime = StringToBool(string(fields[cur]))
	cur++
	ms.Sync = StringToBool(string(fields[cur]))
	cur++
	ms.Hidden = StringToBool(string(fields[cur]))
	return ms
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:37,代碼來源:messagestruct.go

示例12: FetchListStructDecode

// FetchListStructDecode decodes human readable to struct
func FetchListStructDecode(d FetchListStructEncoded) *FetchListStruct {
	if len(d) < FetchListStructMin {
		return nil
	}
	fields := bytes.Fields(d)
	if len(fields) != 2 {
		return nil
	}
	fs := new(FetchListStruct)
	cur := 0
	t := utils.B58decode(string(fields[cur]))
	copy(fs.MessageID[:], t)
	cur++
	fs.TimeEntered, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	return fs
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:17,代碼來源:fetchliststruct.go

示例13: CmdGenTempKey

// CmdGenTempKey generates a temporary key for a given private key
func CmdGenTempKey() int {
	var privkey message.Curve25519Key
	privkeystr := selectPrivKey(OptionsVar.Privkey, GlobalConfigVar.PrivateKey, "tty")
	if privkeystr == "" {
		log.Fatal("No private key given (-privkey)")
		return 1
	}
	copy(privkey[:], utils.B58decode(privkeystr))
	pubkey := message.GenPubKey(&privkey)
	privkeytemp, err := message.GenRandomKey()
	if err != nil {
		log.Errorf("Key generation error:%s\n", err)
		return 1
	}
	pubkeytemp := message.GenPubKey(privkeytemp)
	log.Dataf("STATUS (PrivateKey):\t%s_%s\n", utils.B58encode(privkey[:]), utils.B58encode(privkeytemp[:]))
	log.Dataf("STATUS (PublicKey):\t%s_%s\n", utils.B58encode(pubkey[:]), utils.B58encode(pubkeytemp[:]))
	log.Printf("PRIVATE key: %s_%s\n\n", utils.B58encode(privkey[:]), utils.B58encode(privkeytemp[:]))
	log.Printf("Public key: %s_%s\n", utils.B58encode(pubkey[:]), utils.B58encode(pubkeytemp[:]))
	return 0
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:22,代碼來源:genkey.go

示例14: AuthenticatePeer

// AuthenticatePeer verifies an existing authStr and matches it to the known peers.
func (ms MessageServer) AuthenticatePeer(authStr string) error {
	var counterSig [keyproof.ProofTokenSignedSize]byte
	var auth []byte
	if len(authStr) > keyproof.ProofTokenSignedMax {
		return fmt.Errorf("Bad param")
	}
	auth = utils.B58decode(authStr)
	if len(auth) > keyproof.ProofTokenSignedSize {
		return fmt.Errorf("Bad param")
	}
	copy(counterSig[:], auth)
	ok, timestamp := keyproof.VerifyCounterSig(&counterSig, ms.TokenPubKey)
	if !ok {
		log.Debugs("List:Auth no verify\n")
		return fmt.Errorf("Authentication failed: No match")
	}
	now := CurrentTime()
	if enforceTimeOuts && (timestamp < now-ms.MaxAuthTokenAge-ms.MaxTimeSkew || timestamp > now+ms.MaxAuthTokenAge+ms.MaxTimeSkew) {
		return fmt.Errorf("Authentication failed: Timeout")
	}
	return nil
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:23,代碼來源:getglobalindex.go

示例15: PeerStructDecode

// PeerStructDecode decodes an encoded peer struct
func PeerStructDecode(d PeerStructEncoded) *PeerStruct {
	if len(d) < PeerStructMin {
		return nil
	}
	fields := bytes.Fields(d)
	if len(fields) != 6 {
		return nil
	}
	ps := new(PeerStruct)
	cur := 0
	t := utils.B58decode(string(fields[cur]))
	copy(ps.AuthToken[:], t)
	cur++
	ps.LastNotifySend, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	ps.LastNotifyFrom, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	ps.LastFetch, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	ps.ErrorCount, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	cur++
	ps.LastPosition, _ = strconv.ParseUint(string(fields[cur]), 10, 64)
	return ps
}
開發者ID:carriercomm,項目名稱:repbin,代碼行數:25,代碼來源:peerstruct.go


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