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


Golang Macaroon.Signature方法代码示例

本文整理汇总了Golang中github.com/rogpeppe/macaroon.Macaroon.Signature方法的典型用法代码示例。如果您正苦于以下问题:Golang Macaroon.Signature方法的具体用法?Golang Macaroon.Signature怎么用?Golang Macaroon.Signature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/rogpeppe/macaroon.Macaroon的用法示例。


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

示例1: TestJSONRoundTrip

func (*macaroonSuite) TestJSONRoundTrip(c *gc.C) {
	// jsonData produced from the second example in libmacaroons
	// example README, but with the signature tweaked to
	// match our current behaviour.
	// TODO fix that behaviour so that our signatures match.
	jsonData := `{"caveats":[{"cid":"account = 3735928559"},{"cid":"this was how we remind auth of key\/pred","vid":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA027FAuBYhtHwJ58FX6UlVNFtFsGxQHS7uD\/w\/dedwv4Jjw7UorCREw5rXbRqIKhr","cl":"http:\/\/auth.mybank\/"}],"location":"http:\/\/mybank\/","identifier":"we used our other secret key","signature":"6e315b0b391e8c6cc6f8d88fc22933a13430fb289b2fb613cf70f746bbe7d27d"}`

	var m macaroon.Macaroon
	err := json.Unmarshal([]byte(jsonData), &m)
	c.Assert(err, gc.IsNil)
	c.Assert(hex.EncodeToString(m.Signature()), gc.Equals,
		"6e315b0b391e8c6cc6f8d88fc22933a13430fb289b2fb613cf70f746bbe7d27d")
	data, err := m.MarshalJSON()
	c.Assert(err, gc.IsNil)

	// Check that the round-tripped data is the same as the original
	// data when unmarshalled into an interface{}.
	var got interface{}
	err = json.Unmarshal(data, &got)
	c.Assert(err, gc.IsNil)

	var original interface{}
	err = json.Unmarshal([]byte(jsonData), &original)
	c.Assert(err, gc.IsNil)

	c.Assert(got, gc.DeepEquals, original)
}
开发者ID:jrwren,项目名称:macaroon-bakery,代码行数:27,代码来源:macaroon_test.go

示例2: TestMarshalJSON

func (*macaroonSuite) TestMarshalJSON(c *gc.C) {
	rootKey := []byte("secret")
	m0 := MustNew(rootKey, "some id", "a location")
	m0.AddFirstPartyCaveat("account = 3735928559")
	m0JSON, err := json.Marshal(m0)
	c.Assert(err, gc.IsNil)
	var m1 macaroon.Macaroon
	err = json.Unmarshal(m0JSON, &m1)
	c.Assert(err, gc.IsNil)
	c.Assert(m0.Location(), gc.Equals, m1.Location())
	c.Assert(m0.Id(), gc.Equals, m1.Id())
	c.Assert(
		hex.EncodeToString(m0.Signature()),
		gc.Equals,
		hex.EncodeToString(m1.Signature()))
}
开发者ID:jrwren,项目名称:macaroon-bakery,代码行数:16,代码来源:macaroon_test.go

示例3: hi

func hi(w http.ResponseWriter, r *http.Request, m *macaroon.Macaroon) {
	w.Write([]byte(fmt.Sprintf("hi, your macaroon sig is %s", string(m.Signature()))))
}
开发者ID:rdallman,项目名称:toy-macaroon,代码行数:3,代码来源:server.go


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