pax_global_header00006660000000000000000000000064144756125170014526gustar00rootroot0000000000000052 comment=b7f6c7727eb2bc2d43781bae7448b2ca570e4afa golang-codeberg-gusted-mcaptcha-0.0~git20220723.4f3072e/000077500000000000000000000000001447561251700221705ustar00rootroot00000000000000golang-codeberg-gusted-mcaptcha-0.0~git20220723.4f3072e/.golangci.yml000066400000000000000000000225231447561251700245600ustar00rootroot00000000000000# This file contains all available configuration options # with their default values. # options for analysis running run: # timeout for analysis, e.g. 30s, 5m, default is 1m timeout: 1m # exit code when at least one issue was found, default is 1 issues-exit-code: 1 # include test files or not, default is true tests: true # Allow multiple parallel golangci-lint instances running. # If false (default) - golangci-lint acquires file lock on start. allow-parallel-runners: false # output configuration options output: # colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions # default is "colored-line-number" format: colored-line-number # print lines of code with issue, default is true print-issued-lines: true # print linter name in the end of issue text, default is true print-linter-name: true # make issues output unique by line, default is true uniq-by-line: true # add a prefix to the output file references; default is no prefix path-prefix: "" # sorts results by: filepath, line and column sort-results: true # all available settings of specific linters linters-settings: dogsled: # checks assignments with too many blank identifiers; default is 2 max-blank-identifiers: 2 errcheck: # report about not checking of errors in type assertions: `a := b.(MyStruct)`; # default is false: such cases aren't reported by default. check-type-assertions: false # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; # default is false: such cases aren't reported by default. check-blank: false # list of functions to exclude from checking, where each entry is a single function to exclude. # see https://github.com/kisielk/errcheck#excluding-functions for details exclude-functions: - io/ioutil.ReadFile - io.Copy(*bytes.Buffer) - io.Copy(os.Stdout) errorlint: # Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats errorf: true # Check for plain type assertions and type switches asserts: true # Check for plain error comparisons comparison: true gci: sections: - standard - default - prefix(codeberg.org/Gusted/algorithms-go) gocritic: # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks. # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". enabled-tags: - performance - diagnostic - style - experimental - opinionated # Settings passed to gocritic. # The settings key is the name of a supported gocritic checker. # The list of supported checkers can be find in https://go-critic.github.io/overview. settings: rangeExprCopy: # size in bytes that makes the warning trigger (default 512) sizeThreshold: 32 # whether to check test functions (default true) skipTestFuncs: true rangeValCopy: # size in bytes that makes the warning trigger (default 128) sizeThreshold: 32 # whether to check test functions (default true) skipTestFuncs: true tooManyResultsChecker: # maximum number of results (default 5) maxResults: 10 unnamedResult: # whether to check exported functions checkExported: true godot: # comments to be checked: `declarations`, `toplevel`, or `all` scope: declarations # list of regexps for excluding particular comment lines from check exclude: # example: exclude comments which contain numbers # - '[0-9]+' # check that each sentence starts with a capital letter capital: false gofmt: # simplify code: gofmt with `-s` option, true by default simplify: true gofumpt: # Select the Go version to target. The default is `1.15`. lang-version: "1.18" # Choose whether or not to use the extra rules that are disabled # by default extra-rules: true gosec: # Exclude generated files exclude-generated: true # Filter out the issues with a lower severity than the given value. Valid options are: low, medium, high. severity: "low" # Filter out the issues with a lower confidence than the given value. Valid options are: low, medium, high. confidence: "low" # To specify the configuration of rules. # The configuration of rules is not fully documented by gosec: # https://github.com/securego/gosec#configuration # https://github.com/securego/gosec/blob/569328eade2ccbad4ce2d0f21ee158ab5356a5cf/rules/rulelist.go#L60-L102 config: G306: "0600" gosimple: # Select the Go version to target. The default is '1.13'. go: "1.17" # https://staticcheck.io/docs/options#checks checks: [ "all" ] govet: # report about shadowed variables check-shadowing: true enable-all: true disable-all: false importas: # if set to `true`, force to use alias. no-unaliased: true misspell: # Correct spellings using locale preferences for US or UK. # Default is to use a neutral variety of English. # Setting locale to US will correct the British spelling of 'colour' to 'color'. locale: US nolintlint: # Disable to ensure that all nolint directives actually have an effect. Default is true. allow-unused: true # Disable to ensure that nolint directives don't have a leading space. Default is true. allow-leading-space: true # Exclude following linters from requiring an explanation. Default is []. allow-no-explanation: [ ] # Enable to require an explanation of nonzero length after each nolint directive. Default is false. require-explanation: true # Enable to require nolint directives to mention the specific linter being suppressed. Default is false. require-specific: true prealloc: # XXX: we don't recommend using this linter before doing performance profiling. # For most programs usage of prealloc will be a premature optimization. # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. # True by default. simple: true range-loops: true # Report preallocation suggestions on range loops, true by default for-loops: false # Report preallocation suggestions on for loops, false by default predeclared: # comma-separated list of predeclared identifiers to not report on ignore: "" # include method names and field names (i.e., qualified names) in checks q: true staticcheck: # Select the Go version to target. The default is '1.13'. go: "1.17" # https://staticcheck.io/docs/options#checks checks: [ "all" ] stylecheck: # Select the Go version to target. The default is '1.13'. go: "1.17" # https://staticcheck.io/docs/options#checks checks: [ "all"] # https://staticcheck.io/docs/options#initialisms initialisms: [ "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS" ] # https://staticcheck.io/docs/options#http_status_code_whitelist http-status-code-whitelist: [ "200", "400", "404", "500" ] tagliatelle: # check the struck tag name case case: # use the struct field name to check the name of the struct tag use-field-name: true rules: # any struct tag type can be used. # support string case: `camel`, `pascal`, `kebab`, `snake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower` json: camel yaml: camel xml: camel bson: camel avro: snake mapstructure: kebab thelper: # The following configurations enable all checks. It can be omitted because all checks are enabled by default. # You can enable only required checks deleting unnecessary checks. test: first: true name: true begin: true benchmark: first: true name: true begin: true tb: first: true name: true begin: true unparam: # Inspect exported functions, default is false. Set to true if no external program/library imports your code. # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: # if it's called for subdir of a project it can't find external interfaces. All text editor integrations # with golangci-lint call it on a directory with the changed file. check-exported: false unused: # Select the Go version to target. The default is '1.13'. go: "1.17" linters: disable-all: false enable-all: false enable: - unused - unparam - thelper - tagliatelle - stylecheck - staticcheck - predeclared - prealloc - nolintlint - misspell - importas - govet - gosimple - gosec - gofumpt - gofmt - godot - gocritic - gci - errorlint - errcheck - dogsled fast: false issues: # Maximum issues count per one linter. Set to 0 to disable. Default is 50. max-issues-per-linter: 0 # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. max-same-issues: 0 # Fix found issues (if it's supported by the linter) fix: false severity: default-severity: error golang-codeberg-gusted-mcaptcha-0.0~git20220723.4f3072e/.revive.toml000066400000000000000000000021731447561251700244460ustar00rootroot00000000000000ignoreGeneratedHeader = false severity = "warning" confidence = 0.8 errorCode = 1 warningCode = 1 [rule.blank-imports] [rule.context-as-argument] [rule.context-keys-type] [rule.dot-imports] [rule.error-return] [rule.error-strings] [rule.error-naming] [rule.exported] [rule.if-return] [rule.increment-decrement] [rule.var-naming] [rule.var-declaration] [rule.package-comments] [rule.range] [rule.receiver-naming] [rule.time-naming] [rule.unexported-return] [rule.indent-error-flow] [rule.errorf] [rule.duplicated-imports] [rule.unused-parameter] [rule.useless-break] [rule.defer] [rule.identical-branches] [rule.unconditional-recursion] [rule.early-return] [rule.string-format] [rule.string-of-int] [rule.unused-receiver] [rule.unhandled-error] [rule.import-shadowing] [rule.empty-lines] [rule.waitgroup-by-value] [rule.range-val-address] [rule.range-val-in-closure] [rule.redefines-builtin-id] [rule.bool-literal-in-expr] [rule.constant-logical-expr] [rule.modifies-value-receiver] [rule.unnecessary-stmt] [rule.unreachable-code] [rule.confusing-results] [rule.modifies-parameter] [rule.get-return] [rule.confusing-naming] [rule.superfluous-else] golang-codeberg-gusted-mcaptcha-0.0~git20220723.4f3072e/.woodpecker/000077500000000000000000000000001447561251700244105ustar00rootroot00000000000000golang-codeberg-gusted-mcaptcha-0.0~git20220723.4f3072e/.woodpecker/config.yml000066400000000000000000000003221447561251700263750ustar00rootroot00000000000000pipeline: lint: image: golang commands: - go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2 run ./... - go run github.com/mgechev/revive@v1.2.1 -config .revive.toml ./... golang-codeberg-gusted-mcaptcha-0.0~git20220723.4f3072e/LICENSE000066400000000000000000000020471447561251700232000ustar00rootroot00000000000000Copyright © 2022 William Zijl Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. golang-codeberg-gusted-mcaptcha-0.0~git20220723.4f3072e/README.md000066400000000000000000000005251447561251700234510ustar00rootroot00000000000000# mCaptcha Go mCaptcha is a Go library to interact with [mCaptcha](https://github.com/mCaptcha/mCaptcha). ## Implemented The library currently only implements the PoW verification endpoint and not an of the other endpoints. [Check the documentation](https://pkg.go.dev/codeberg.org/gusted/mcaptcha) for currently implemented functions. golang-codeberg-gusted-mcaptcha-0.0~git20220723.4f3072e/errors.go000066400000000000000000000006471447561251700240420ustar00rootroot00000000000000package mcaptcha import "errors" var ( // ErrMissingSecret errors when no secret was provided by the code. ErrMissingSecret = errors.New("no secret was provided") // ErrMissingSitekey errors when no sitekey was provided by the code. ErrMissingSitekey = errors.New("no sitekey was provided") // ErrMissingToken errors when no token was provided by the code. ErrMissingToken = errors.New("no token was provided") ) golang-codeberg-gusted-mcaptcha-0.0~git20220723.4f3072e/go.mod000066400000000000000000000000551447561251700232760ustar00rootroot00000000000000module codeberg.org/gusted/mcaptcha go 1.18 golang-codeberg-gusted-mcaptcha-0.0~git20220723.4f3072e/mcaptcha.go000066400000000000000000000040261447561251700243010ustar00rootroot00000000000000package mcaptcha import ( "bytes" "context" "encoding/json" "fmt" "io" "net/http" "strings" ) // VerifyOpts holds all the information that is need to make a verification request. type VerifyOpts struct { Secret string `json:"secret"` Sitekey string `json:"key"` //nolint:tagliatelle // `Sitekey` is the correct naming, but API expects `key`. Token string `json:"token"` InstanceURL string `json:"-"` } // GetOpts returns a io.Reader that contains a JSON representation // of the options. func (opts *VerifyOpts) GetOpts() (io.Reader, error) { if opts.Secret == "" { return nil, ErrMissingSecret } if opts.Sitekey == "" { return nil, ErrMissingSitekey } if opts.Token == "" { return nil, ErrMissingToken } body, err := json.Marshal(opts) if err != nil { return nil, fmt.Errorf("couldn't marshal options: %w", err) } return bytes.NewReader(body), nil } type verifyResponse struct { Valid bool `json:"valid"` } // Verify takes in a context and options to make a verification request. // It will verify if the given token is validated on the given mCaptcha instance. func Verify(ctx context.Context, opts *VerifyOpts) (bool, error) { body, err := opts.GetOpts() if err != nil { return false, err } url := strings.TrimSuffix(opts.InstanceURL, "/") req, err := http.NewRequestWithContext(ctx, "POST", url+"/api/v1/pow/siteverify", body) if err != nil { return false, fmt.Errorf("couldn't create a new request: %w", err) } req.Header.Set("Content-Type", "application/json") res, err := http.DefaultClient.Do(req) if err != nil { return false, fmt.Errorf("couldn't execute request: %w", err) } defer res.Body.Close() if res.StatusCode != 200 { content, _ := io.ReadAll(res.Body) return false, fmt.Errorf("mCaptcha didn't return 200 OK [content=%q]", string(content)) } var responseStruct verifyResponse err = json.NewDecoder(res.Body).Decode(&responseStruct) if err != nil { return false, fmt.Errorf("couldn't decode response from mCaptcha: %w", err) } return responseStruct.Valid, nil }