Ejemplo n.º 1
0
func (self *restContext) ReadBucketId(value *httpserver.Values, key string, optional bool) (
	bucketId bucket.Id,
	bucketIdAsString string,
	status retcode.Status) {

	if optional {
		bucketIdAsString = value.OptionalString(key)
		if bucketIdAsString == "" {
			return
		}
	} else {
		bucketIdAsString, status = value.NonEmptyString(key)
		if !status.IsOk() {
			return
		}
	}

	bucketIdBytes, err := encoding.Base32Decode(bucketIdAsString)
	if err != nil {
		status = retcode.NewStatusFmt(retcode.ErrorClient, "Invalid bucket id given. The id "+
			"has to be base32 without padding. Err: %v", err)
		return
	}
	bucketId = bucket.Id(bucketIdBytes)
	status = retcode.NewStatusOk()
	return
}
Ejemplo n.º 2
0
func FromString(str string) (userId Id, err error) {
	bytes, err := encoding.Base32Decode(str)
	if err != nil {
		return
	}
	possibleUserId := Id(bytes)
	if !possibleUserId.IsValid() {
		err = errors.New(fmt.Sprintf("The given string '%v' is not a valid user id.", str))
		return
	}
	return possibleUserId, nil
}
Ejemplo n.º 3
0
func (self *Converter) ReadBase32(input interface{}) []byte {
	if input == nil {
		panic("Expecting a value, but it's missing")
	}
	switch input := input.(type) {
	case string:
		byteVal, err := encoding.Base32Decode(input)
		if err != nil {
			panic(fmt.Sprintf("Expecting a base32 string but got %v", input))
		}
		return byteVal
	default:
		panic(fmt.Sprintf("Expecting a base32 string but got a %T", input))
	}
}
Ejemplo n.º 4
0
func (self *restContext) ReadShaHashAsBinary(value *httpserver.Values, key string) (
	hashBytes []byte,
	hashString string,
	status retcode.Status) {

	hashString, status = value.NonEmptyString(key)
	if !status.IsOk() {
		return
	}
	hashBytes, err := encoding.Base32Decode(hashString)
	if err != nil {
		status = retcode.NewStatusFmt(retcode.ErrorClient, "Invalid hash given. The hash "+
			"has to be base32 without padding. Err: %v", err)
		return
	}
	return
}
Ejemplo n.º 5
0
func (self *restServer) directoryGet(ctx *restContext) {
	var status retcode.Status

	hashAsString, status := ctx.UrlParams.NonEmptyString("hash")
	if !status.IsOk() {
		ctx.WriteErrorStatus(status)
		return
	}
	hash, err := encoding.Base32Decode(hashAsString)
	if err != nil {
		status = retcode.NewStatusFmt(retcode.ErrorClient, "Hash does not seem to be a base32 hash")
		ctx.WriteErrorStatus(status)
		return
	}

	filenames := directorySubPath(ctx.UrlParams, ctx)

	curEntry := &directoryEntry{
		isDirectory: true,
		targetHash:  hash,
	}
	finalEntry, found, status := directoryGetMultiple(ctx, curEntry, filenames)
	if !found {
		status = retcode.NewStatusFmt(retcode.OkNotFound, "Entry not found")
		ctx.WriteErrorStatus(status)
		return
	}

	if finalEntry.isDirectory {
		// Output all files from directory as json
		directoryOutputAsJson(ctx, finalEntry)
	} else {
		// Redirect to blobget
		hash := finalEntry.targetHash
		hashAsString := encoding.Base32Encode(hash)
		mime := finalEntry.mimeType
		self.blobGetWithParams(ctx, hash, hashAsString, nil, mime)
	}
}
Ejemplo n.º 6
0
func Base32(payload string) (data []byte, err error) {
	return encoding.Base32Decode(payload)
}