当前位置: 首页>>代码示例>>Golang>>正文


Golang hex.DecodeString函数代码示例

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


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

示例1: readConfig

// reads the configuration file from the path specified by
// the config command line flag.
func readConfig(configFile string) error {
	b, err := ioutil.ReadFile(configFile)
	if err != nil {
		return err
	}
	err = json.Unmarshal(b, &config)
	if err != nil {
		return err
	}
	cookieAuthKey, err = hex.DecodeString(*config.CookieAuthKeyHexStr)
	if err != nil {
		return err
	}
	cookieEncrKey, err = hex.DecodeString(*config.CookieEncrKeyHexStr)
	if err != nil {
		return err
	}
	secureCookie = securecookie.New(cookieAuthKey, cookieEncrKey)
	// verify auth/encr keys are correct
	val := map[string]string{
		"foo": "bar",
	}
	_, err = secureCookie.Encode(cookieName, val)
	if err != nil {
		// for convenience, if the auth/encr keys are not set,
		// generate valid, random value for them
		auth := securecookie.GenerateRandomKey(32)
		encr := securecookie.GenerateRandomKey(32)
		fmt.Printf("auth: %s\nencr: %s\n", hex.EncodeToString(auth), hex.EncodeToString(encr))
	}
	// TODO: somehow verify twitter creds
	return err
}
开发者ID:uwydoc,项目名称:web-blog,代码行数:35,代码来源:main.go

示例2: TestAmqp_GetEmptyMethod

func TestAmqp_GetEmptyMethod(t *testing.T) {
	if testing.Verbose() {
		logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
	}

	amqp := amqpModForTests()
	amqp.sendRequest = true

	data, err := hex.DecodeString("01000100000013003c004600000b526f626269" +
		"654b65616e6501ce")
	assert.Nil(t, err)
	data2, err := hex.DecodeString("01000100000005003c004800ce")
	assert.Nil(t, err)

	tcptuple := testTCPTuple()

	req := protos.Packet{Payload: data}
	private := protos.ProtocolData(new(amqpPrivateData))
	private = amqp.Parse(&req, tcptuple, 0, private)
	req = protos.Packet{Payload: data2}
	amqp.Parse(&req, tcptuple, 1, private)

	trans := expectTransaction(t, amqp)
	assert.Equal(t, "basic.get-empty", trans["method"])
	assert.Equal(t, "basic.get RobbieKeane", trans["request"])
	assert.Equal(t, "amqp", trans["type"])
	assert.Equal(t, common.OK_STATUS, trans["status"])
}
开发者ID:ruflin,项目名称:beats,代码行数:28,代码来源:amqp_test.go

示例3: TestAmqp_RecoverMethod

func TestAmqp_RecoverMethod(t *testing.T) {
	if testing.Verbose() {
		logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
	}

	amqp := amqpModForTests()
	amqp.sendRequest = true

	data, err := hex.DecodeString("01000100000005003c006e01ce")
	assert.Nil(t, err)
	data2, err := hex.DecodeString("01000100000004003c006fce")
	assert.Nil(t, err)

	tcptuple := testTCPTuple()

	req := protos.Packet{Payload: data}
	private := protos.ProtocolData(new(amqpPrivateData))
	private = amqp.Parse(&req, tcptuple, 0, private)
	req = protos.Packet{Payload: data2}
	amqp.Parse(&req, tcptuple, 1, private)

	trans := expectTransaction(t, amqp)
	assert.Equal(t, "basic.recover", trans["method"])
	assert.Equal(t, "basic.recover", trans["request"])
	assert.Equal(t, "amqp", trans["type"])
	assert.Equal(t, common.OK_STATUS, trans["status"])
	assert.Equal(t, common.MapStr{"requeue": true}, trans["amqp"])
}
开发者ID:ruflin,项目名称:beats,代码行数:28,代码来源:amqp_test.go

示例4: Bond

func Bond(nodeAddr, pubkey, unbondAddr, amtS, nonceS string) (*types.BondTx, error) {
	pub, addrBytes, amt, nonce, err := checkCommon(nodeAddr, pubkey, "", amtS, nonceS)
	if err != nil {
		return nil, err
	}
	var pubKey account.PubKeyEd25519
	var unbondAddrBytes []byte

	if unbondAddr == "" {
		pkb, _ := hex.DecodeString(pubkey)
		copy(pubKey[:], pkb)
		unbondAddrBytes = pubKey.Address()
	} else {
		unbondAddrBytes, err = hex.DecodeString(unbondAddr)
		if err != nil {
			return nil, fmt.Errorf("unbondAddr is bad hex: %v", err)
		}

	}

	tx, err := types.NewBondTx(pub)
	if err != nil {
		return nil, err
	}
	_ = addrBytes
	tx.AddInputWithNonce(pub, amt, int(nonce))
	tx.AddOutput(unbondAddrBytes, amt)

	return tx, nil
}
开发者ID:GetLevvel,项目名称:blockchain-digital-notary,代码行数:30,代码来源:core.go

示例5: TestAmqp_ConnectionCloseNoError

func TestAmqp_ConnectionCloseNoError(t *testing.T) {
	if testing.Verbose() {
		logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
	}

	amqp := amqpModForTests()
	amqp.hideConnectionInformation = false

	data, err := hex.DecodeString("01000000000012000a003200c8076b74687862616900000000ce")
	assert.Nil(t, err)
	data2, err := hex.DecodeString("01000000000004000a0033ce")
	assert.Nil(t, err)

	tcptuple := testTCPTuple()

	req := protos.Packet{Payload: data}
	private := protos.ProtocolData(new(amqpPrivateData))
	private = amqp.Parse(&req, tcptuple, 0, private)
	req = protos.Packet{Payload: data2}
	amqp.Parse(&req, tcptuple, 1, private)

	trans := expectTransaction(t, amqp)
	assert.Equal(t, "connection.close", trans["method"])
	assert.Equal(t, "amqp", trans["type"])
	assert.Equal(t, common.OK_STATUS, trans["status"])
	assert.Nil(t, trans["notes"])

	fields, ok := trans["amqp"].(common.MapStr)
	assert.True(t, ok)
	code, ok := fields["reply-code"].(uint16)
	assert.True(t, ok)
	assert.Equal(t, uint16(200), code)
}
开发者ID:ruflin,项目名称:beats,代码行数:33,代码来源:amqp_test.go

示例6: addCerts

func addCerts(csvFilename string, dbMap *gorp.DbMap, stats metrics.Statter, statsRate float32) {
	file, err := os.Open(csvFilename)
	cmd.FailOnError(err, "Could not open the file for reading")
	csvReader := csv.NewReader(file)

	for {
		record, err := csvReader.Read()
		if err == io.EOF {
			break
		} else if err != nil {
			fmt.Println("Error:", err)
			return
		}

		notAfter, err := time.Parse(datestampFormat, record[3])
		spkiBytes, err := hex.DecodeString(record[4])
		certDER, err := hex.DecodeString(record[7])

		externalCert := core.ExternalCert{
			SHA1:     record[0],
			Issuer:   record[1],
			Subject:  record[2],
			NotAfter: notAfter,
			SPKI:     spkiBytes,
			Valid:    record[5] == "1",
			EV:       record[6] == "1",
			CertDER:  certDER,
		}

		importStart := time.Now()
		err = dbMap.Insert(&externalCert)
		stats.TimingDuration("ExistingCert.Certs.ImportLatency", time.Since(importStart), statsRate)
		stats.Inc("ExistingCert.Certs.Imported", 1, statsRate)
	}
}
开发者ID:patf,项目名称:boulder,代码行数:35,代码来源:main.go

示例7: TestAesKeyWrapInvalid

func TestAesKeyWrapInvalid(t *testing.T) {
	kek, _ := hex.DecodeString("000102030405060708090A0B0C0D0E0F")

	// Invalid unwrap input (bit flipped)
	input0, _ := hex.DecodeString("1EA68C1A8112B447AEF34BD8FB5A7B828D3E862371D2CFE5")

	block, _ := aes.NewCipher(kek)

	_, err := KeyUnwrap(block, input0)
	if err == nil {
		t.Error("key unwrap failed to detect invalid input")
	}

	// Invalid unwrap input (truncated)
	input1, _ := hex.DecodeString("1EA68C1A8112B447AEF34BD8FB5A7B828D3E862371D2CF")

	_, err = KeyUnwrap(block, input1)
	if err == nil {
		t.Error("key unwrap failed to detect truncated input")
	}

	// Invalid wrap input (not multiple of 8)
	input2, _ := hex.DecodeString("0123456789ABCD")

	_, err = KeyWrap(block, input2)
	if err == nil {
		t.Error("key wrap accepted invalid input")
	}

}
开发者ID:CometKim,项目名称:platform,代码行数:30,代码来源:key_wrap_test.go

示例8: TestGeneralSecp256k1

func TestGeneralSecp256k1(t *testing.T) {
	// Sample expanded pubkey (Satoshi from Genesis block)
	samplePubkey, _ := hex.DecodeString("04" +
		"678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb6" +
		"49f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")
	_, err := Secp256k1.ParsePubKey(samplePubkey)
	if err != nil {
		t.Errorf("failure parsing pubkey: %v", err)
	}

	// Sample compressed pubkey
	samplePubkey, _ = hex.DecodeString("02" +
		"4627032575180c2773b3eedd3a163dc2f3c6c84f9d0a1fc561a9578a15e6d0e3")
	_, err = Secp256k1.ParsePubKey(samplePubkey)
	if err != nil {
		t.Errorf("failure parsing pubkey: %v", err)
	}

	// Sample signature from https://en.bitcoin.it/wiki/Transaction
	sampleSig, _ := hex.DecodeString("30" +
		"45" +
		"02" +
		"20" +
		"6e21798a42fae0e854281abd38bacd1aeed3ee3738d9e1446618c4571d1090db" +
		"02" +
		"21" +
		"00e2ac980643b0b82c0e88ffdfec6b64e3e6ba35e7ba5fdd7d5d6cc8d25c6b2415")
	_, err = Secp256k1.ParseDERSignature(sampleSig)
	if err != nil {
		t.Errorf("failure parsing DER signature: %v", err)
	}
}
开发者ID:decred,项目名称:dcrd,代码行数:32,代码来源:secp256k1_test.go

示例9: TestVerify

func TestVerify(t *testing.T) {
	pkey, _ := hex.DecodeString("040eaebcd1df2df853d66ce0e1b0fda07f67d1cabefde98514aad795b86a6ea66dbeb26b67d7a00e2447baeccc8a4cef7cd3cad67376ac1c5785aeebb4f6441c16")
	hasz, _ := hex.DecodeString("3382219555ddbb5b00e0090f469e590ba1eae03c7f28ab937de330aa60294ed6")
	sign, _ := hex.DecodeString("3045022100fe00e013c244062847045ae7eb73b03fca583e9aa5dbd030a8fd1c6dfcf11b1002207d0d04fed8fa1e93007468d5a9e134b0a7023b6d31db4e50942d43a250f4d07c01")
	res := EC_Verify(pkey, sign, hasz)
	if res != 1 {
		t.Error("Verify failed")
	}
	hasz[0]++
	res = EC_Verify(pkey, sign, hasz)
	if res != 0 {
		t.Error("Verify not failed while it should")
	}
	res = EC_Verify(pkey[:1], sign, hasz)
	if res >= 0 {
		t.Error("Negative result expected", res)
	}
	res = EC_Verify(pkey, sign[:1], hasz)
	if res >= 0 {
		t.Error("Yet negative result expected", res)
	}
	res = EC_Verify(pkey, sign, hasz[:1])
	if res != 0 {
		t.Error("Zero expected", res)
	}
}
开发者ID:liudch,项目名称:gocoin,代码行数:26,代码来源:sipadll_test.go

示例10: listenDaemon

func (repo *postgresRepository) listenDaemon() error {
	doneCh := registry.DoneChannel()
	pqNotificationCh := repo.listener.NotificationChannel()

	for {
		select {
		case <-doneCh:
			return nil
		case pqNotification, ok := <-pqNotificationCh:
			if !ok {
				return nil
			}

			decodedChannel, err := hex.DecodeString(pqNotification.Channel[1:]) // trim leading '_'
			if err != nil {
				return err
			}

			decodedPayload, err := hex.DecodeString(pqNotification.Extra)
			if err != nil {
				return err
			}

			repo.m.RLock()
			for ch := range repo.listenChannels[string(decodedChannel)] {
				ch <- string(decodedPayload)
			}
			repo.m.RUnlock()
		}
	}
}
开发者ID:eklementev,项目名称:esp,代码行数:31,代码来源:postgres.go

示例11: parseReadHeaders

func parseReadHeaders(s string) (info ReadInfo, err error) {
	headers := strings.Split(s, ",")
	if len(headers) < 3 {
		err = fmt.Errorf("error: Split headers failed: %s", s)
		return
	}

	node, derr := hex.DecodeString(headers[0])
	if derr != nil {
		err = fmt.Errorf("error: Decode Node failed (%s): %s", headers[0], derr)
		return
	}
	info.FromNode = Node(node[0])

	id, derr := strToUint16(headers[1])
	if err != nil {
		err = fmt.Errorf("error: Decode FromId failed (%s): %s", headers[1], derr)
		return
	}
	info.FromId = Id(id)

	rssi, derr := hex.DecodeString(headers[2])
	if err != nil {
		err = fmt.Errorf("error: Decode Rssi failed (%s): %s", headers[2], derr)
		return
	}
	info.FromRssi = Rssi(rssi[0])

	return
}
开发者ID:tomoya0x00,项目名称:go-im920,代码行数:30,代码来源:im920.go

示例12: TestVerify1

func TestVerify1(t *testing.T) {
	for i := range ta {
		pkey, _ := hex.DecodeString(ta[i][0])
		sign, _ := hex.DecodeString(ta[i][1])
		hasz, _ := hex.DecodeString(ta[i][2])

		res := ecdsa_verify(pkey, sign, hasz)
		if res != 1 {
			t.Fatal("Verify failed at", i)
		}

		hasz[0]++
		res = ecdsa_verify(pkey, sign, hasz)
		if res != 0 {
			t.Error("Verify not failed while it should", i)
		}
		res = ecdsa_verify(pkey[:1], sign, hasz)
		if res >= 0 {
			t.Error("Negative result expected", res, i)
		}
		res = ecdsa_verify(pkey, sign[:1], hasz)
		if res >= 0 {
			t.Error("Yet negative result expected", res, i)
		}
		res = ecdsa_verify(pkey, sign, hasz[:1])
		if res != 0 {
			t.Error("Zero expected", res, i)
		}
	}
}
开发者ID:Chao-Jia,项目名称:skycoin,代码行数:30,代码来源:ec_test.go

示例13: ParseShardingSpec

// ParseShardingSpec parses a string that describes a sharding
// specification. a-b-c-d will be parsed as a-b, b-c, c-d. The empty
// string may serve both as the start and end of the keyspace: -a-b-
// will be parsed as start-a, a-b, b-end.
func ParseShardingSpec(spec string) ([]*topodatapb.KeyRange, error) {
	parts := strings.Split(spec, "-")
	if len(parts) == 1 {
		return nil, fmt.Errorf("malformed spec: doesn't define a range: %q", spec)
	}
	old := parts[0]
	ranges := make([]*topodatapb.KeyRange, len(parts)-1)

	for i, p := range parts[1:] {
		if p == "" && i != (len(parts)-2) {
			return nil, fmt.Errorf("malformed spec: MinKey/MaxKey cannot be in the middle of the spec: %q", spec)
		}
		if p != "" && p <= old {
			return nil, fmt.Errorf("malformed spec: shard limits should be in order: %q", spec)
		}
		s, err := hex.DecodeString(old)
		if err != nil {
			return nil, err
		}
		if len(s) == 0 {
			s = nil
		}
		e, err := hex.DecodeString(p)
		if err != nil {
			return nil, err
		}
		if len(e) == 0 {
			e = nil
		}
		ranges[i] = &topodatapb.KeyRange{Start: s, End: e}
		old = p
	}
	return ranges, nil
}
开发者ID:dumbunny,项目名称:vitess,代码行数:38,代码来源:key.go

示例14: TestParse_LibbitconTX

func TestParse_LibbitconTX(t *testing.T) {
	txData, err := hex.DecodeString(consensusScriptVerifyTx)
	if err != nil {
		t.Fatalf("Error decoding HEX tx from libbitcoin:  %s", err)
		return
	}

	prevTxScript, err := hex.DecodeString(consensusScriptVerifyPreviousOutputScript)
	if err != nil {
		t.Fatalf("Error decoding HEX tx from libbitcoin:  %s", err)
		return
	}

	t.Logf("TX data from libbitcoin: %v", txData)

	tx := ParseUTXOBytes(txData)

	// Call Verify_script
	txInputIndex := uint(0)
	result := consensus.Verify_script(&txData[0], int64(len(txData)), &prevTxScript[0], int64(len(prevTxScript)), txInputIndex, uint(consensus.Verify_flags_p2sh))
	if result != consensus.Verify_result_eval_true {
		t.Fatalf("Unexpected result from verify_script, expected %d, got %d", consensus.Verify_result_eval_true, result)
	}
	t.Log(result)
	t.Log(consensus.Verify_result_eval_true)
	t.Logf("TX from %v", tx)
}
开发者ID:C0rWin,项目名称:fabric,代码行数:27,代码来源:utxo_test.go

示例15: handleConnection

func handleConnection(n net.Conn) {
	l := make([]byte, 1024)
	_, err := n.Read(l)
	if err != nil {
		panic("server read error")
	}

	// Bind Resp
	d, _ := hex.DecodeString("000000158000000900000000000000016875676f00")
	n.Write(d)

	time.Sleep(100 * time.Millisecond)

	// Invalid CMD ID
	d, _ = hex.DecodeString("0000001090000015000000005222b523")
	n.Write(d)

	time.Sleep(100 * time.Millisecond)

	// PDU Len different than read bytes
	d, _ = hex.DecodeString("000000178000000900000000000000016875676f00")
	n.Write(d)

	time.Sleep(100 * time.Millisecond)

	// Max PDU Len err
	d, _ = hex.DecodeString("0000F01080000015000000005222b526")
	n.Write(d)
}
开发者ID:XmsCoders,项目名称:smpp34,代码行数:29,代码来源:smpp_test.go


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