// WrapOpID returns HMAC-protected string that embeds upload operation ID.
//
// The string is bound to the given caller, i.e UnwrapOpID will correctly
// validate HMAC only if it receives the exact same caller.
550333
func WrapOpID(c context.Context, id int64, caller identity.Identity) (string, error) {
	return opToken.Generate(c, []byte(caller), map[string]string{
		"id": strconv.FormatInt(id, 10),
	}, 0)
}
1030250
func getAzureUploadID() (string, error) {
	var id [8]byte

	n, err := io.ReadFull(rand.Reader, id[:])
	if err != nil {
		return "", err
	}
	if n != len(id) {
		return "", fmt.Errorf("Unexpected random data size. Expected: %d, read: %d)", len(id), n)
	}

	return hex.EncodeToString(id[:]), nil
}
965906
func (p *OAuth) Wrapper(e *echo.Echo, middlewares ...interface{}) {
	p.Config.GenerateProviders()

	g := e.Group(p.Config.Path, middlewares...)

	// set the mux path to handle the registered providers
	g.Get("/login/:provider", p.beginAuthHandler)

	authMiddleware := func(h echo.Handler) echo.Handler {
		return echo.HandlerFunc(func(ctx echo.Context) error {
			user, err := p.completeAuthHandler(ctx)
			if err != nil {
				return echo.NewHTTPError(http.StatusUnauthorized, err.Error())
			}
			ctx.Set(p.Config.ContextKey, user)
			return h.Handle(ctx)
		})
	}

	p.successHandlers = append([]interface{}{authMiddleware}, p.successHandlers...)
	lastIndex := len(p.successHandlers) - 1
	if lastIndex == 0 {
		g.Get("/callback/:provider", func(ctx echo.Context) error {
			return ctx.String(`Success Handler is not set`)
		}, p.successHandlers...)
	} else {
		g.Get("/callback/:provider", p.successHandlers[lastIndex], p.successHandlers[0:lastIndex]...)
	}
	// register the error handler
	if p.failHandler != nil {
		e.SetHTTPErrorHandler(p.failHandler)
	}
}
111399
func UnwrapResponseAPDU(channel uint16, dev <-chan []byte, packetSize int, ble bool) ([]byte, error) {
	var err error
	var sequenceIdx uint16
	var extraHeaderSize int
	if !ble {
		extraHeaderSize = 2
	}
	buf := <-dev
	if len(buf) < 5+extraHeaderSize+5 {
		return nil, errTooShort
	}

	buf, err = validatePrefix(buf, channel, sequenceIdx, ble)
	if err != nil {
		return nil, err
	}

	responseLength := int(codec.Uint16(buf))
	buf = buf[2:]
	result := make([]byte, responseLength)
	out := result

	blockSize := packetSize - 5 - extraHeaderSize
	if blockSize > len(buf) {
		blockSize = len(buf)
	}
	copy(out, buf[:blockSize])

	// if there is anything left to read...
	for len(out) > blockSize {
		out = out[blockSize:]
		buf = <-dev

		sequenceIdx++
		buf, err = validatePrefix(buf, channel, sequenceIdx, ble)
		if err != nil {
			return nil, err
		}

		blockSize = packetSize - 3 - extraHeaderSize
		if blockSize > len(buf) {
			blockSize = len(buf)
		}
		copy(out, buf[:blockSize])
	}
	return result, nil
}
1066296
func (a *Client) PatchLookupsID(params *PatchLookupsIDParams, authInfo runtime.ClientAuthInfoWriter) (*PatchLookupsIDOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewPatchLookupsIDParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "PatchLookupsID",
		Method:             "PATCH",
		PathPattern:        "/lookups/{id}",
		ProducesMediaTypes: []string{"application/json", "application/x-gzip"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http", "https"},
		Params:             params,
		Reader:             &PatchLookupsIDReader{formats: a.formats},
		AuthInfo:           authInfo,
	})
	if err != nil {
		return nil, err
	}
	return result.(*PatchLookupsIDOK), nil
}
432237
func (b *Bslack) handleTopicOrPurpose(msg *config.Message, channelInfo *slack.Channel) (bool, error) {
	if msg.Event != config.EventTopicChange {
		return false, nil
	}

	if b.GetBool("SyncTopic") {
		return true, b.updateTopicOrPurpose(msg, channelInfo)
	}

	// Pass along to normal message handlers.
	if b.GetBool("ShowTopicChange") {
		return false, nil
	}

	// Swallow message as handled no-op.
	return true, nil
}
724052
func fetchOp(c context.Context, wrappedOpID string) (*upload.Operation, error) {
	opID, err := upload.UnwrapOpID(c, wrappedOpID, auth.CurrentIdentity(c))
	if err != nil {
		if transient.Tag.In(err) {
			return nil, errors.Annotate(err, "failed to check HMAC on upload_operation_id").Err()
		}
		return nil, errors.Reason("no such upload operation").
			InternalReason("HMAC check failed - %s", err).
			Tag(grpcutil.NotFoundTag).Err()
	}

	op := &upload.Operation{ID: opID}
	switch err := datastore.Get(c, op); {
	case err == datastore.ErrNoSuchEntity:
		return nil, errors.Reason("no such upload operation").
			Tag(grpcutil.NotFoundTag).Err()
	case err != nil:
		return nil, errors.Annotate(err, "failed to fetch the upload operation").
			Tag(grpcutil.InternalTag).Err()
	}

	return op, nil
}
454193
func (s *CompleteMultipartUploadInput) SetUploadId(v string) *CompleteMultipartUploadInput {
	s.UploadId = &v
	return s
}
1288090
func (o *GetServiceIDParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error {
	var raw string
	if len(rawData) > 0 {
		raw = rawData[len(rawData)-1]
	}

	// Required: true
	// Parameter is provided by construction from the route

	value, err := swag.ConvertInt64(raw)
	if err != nil {
		return errors.InvalidType("id", "path", "int64", raw)
	}
	o.ID = value

	return nil
}
939603
func (rt *upgradeRequestRoundTripper) WrapRequest(req *http.Request) (*http.Request, error) {
	resp, err := rt.upgrader.RoundTrip(req)
	if err != nil {
		return nil, err
	}
	return resp.Request, nil
}
1264819
func unwrapOutput(i interface{}) (interface{}, error) {
	var (
		ch <-chan interface{}
		ok bool
	)

	if ch, ok = i.(<-chan interface{}); !ok {
		return nil, e.TypeErr(ch, i)
	}

	return <-ch, nil
}
684481
func (locker *Etcd3Locker) LockUpload(id string) error {
	session, err := locker.createSession()
	if err != nil {
		return err
	}

	lock := newEtcd3Lock(session, locker.getId(id))

	err = lock.Acquire()
	if err != nil {
		return err
	}

	locker.mutex.Lock()
	defer locker.mutex.Unlock()
	// Only add the lock to our list if the acquire was successful and no error appeared.
	locker.locks[locker.getId(id)] = lock

	return nil
}
1284302
func (lk *localKeys) lookupID(id idpool.ID) string {
	lk.RLock()
	defer lk.RUnlock()

	if k, ok := lk.ids[id]; ok {
		return k.key
	}

	return ""
}
822501
func WrapHandler(h interface{}) Handler {
	if v, ok := h.(HandlerFunc); ok {
		return v
	}
	if v, ok := h.(Handler); ok {
		return v
	}
	if v, ok := h.(func(Context) error); ok {
		return HandlerFunc(v)
	}
	if v, ok := h.(http.Handler); ok {
		return HandlerFunc(func(ctx Context) error {
			v.ServeHTTP(ctx.Response().StdResponseWriter(), ctx.Request().StdRequest())
			return nil
		})
	}
	if v, ok := h.(func(http.ResponseWriter, *http.Request)); ok {
		return HandlerFunc(func(ctx Context) error {
			v(ctx.Response().StdResponseWriter(), ctx.Request().StdRequest())
			return nil
		})
	}
	if v, ok := h.(func(http.ResponseWriter, *http.Request) error); ok {
		return HandlerFunc(func(ctx Context) error {
			return v(ctx.Response().StdResponseWriter(), ctx.Request().StdRequest())
		})
	}
	panic(`unknown handler`)
}
1338226
func (s *AbortMultipartUploadInput) SetUploadId(v string) *AbortMultipartUploadInput {
	s.UploadId = &v
	return s
}
496454
func (locker *Etcd3Locker) UnlockUpload(id string) error {
	locker.mutex.Lock()
	defer locker.mutex.Unlock()

	// Complain if no lock has been found. This can only happen if LockUpload
	// has not been invoked before or UnlockUpload multiple times.
	lock, ok := locker.locks[locker.getId(id)]
	if !ok {
		return ErrLockNotHeld
	}

	err := lock.Release()
	if err != nil {
		return err
	}

	defer delete(locker.locks, locker.getId(id))
	return lock.CloseSession()
}
722689
func OptDeviceID(id int) Option {
	return func(h *HCI) error {
		h.id = id
		return nil
	}
}