mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Update github.com/pquerna/otp from untagged to v1.2.0 (#11358)
This commit is contained in:
		
							
								
								
									
										22
									
								
								vendor/github.com/pquerna/otp/totp/totp.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										22
									
								
								vendor/github.com/pquerna/otp/totp/totp.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -134,14 +134,18 @@ type GenerateOpts struct { | ||||
| 	AccountName string | ||||
| 	// Number of seconds a TOTP hash is valid for. Defaults to 30 seconds. | ||||
| 	Period uint | ||||
| 	// Size in size of the generated Secret. Defaults to 10 bytes. | ||||
| 	// Size in size of the generated Secret. Defaults to 20 bytes. | ||||
| 	SecretSize uint | ||||
| 	// Secret to store. Defaults to a randomly generated secret of SecretSize.  You should generally leave this empty. | ||||
| 	Secret []byte | ||||
| 	// Digits to request. Defaults to 6. | ||||
| 	Digits otp.Digits | ||||
| 	// Algorithm to use for HMAC. Defaults to SHA1. | ||||
| 	Algorithm otp.Algorithm | ||||
| } | ||||
|  | ||||
| var b32NoPadding = base32.StdEncoding.WithPadding(base32.NoPadding) | ||||
|  | ||||
| // Generate a new TOTP Key. | ||||
| func Generate(opts GenerateOpts) (*otp.Key, error) { | ||||
| 	// url encode the Issuer/AccountName | ||||
| @@ -158,7 +162,7 @@ func Generate(opts GenerateOpts) (*otp.Key, error) { | ||||
| 	} | ||||
|  | ||||
| 	if opts.SecretSize == 0 { | ||||
| 		opts.SecretSize = 10 | ||||
| 		opts.SecretSize = 20 | ||||
| 	} | ||||
|  | ||||
| 	if opts.Digits == 0 { | ||||
| @@ -168,13 +172,17 @@ func Generate(opts GenerateOpts) (*otp.Key, error) { | ||||
| 	// otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example | ||||
|  | ||||
| 	v := url.Values{} | ||||
| 	secret := make([]byte, opts.SecretSize) | ||||
| 	_, err := rand.Read(secret) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	if len(opts.Secret) != 0 { | ||||
| 		v.Set("secret", b32NoPadding.EncodeToString(opts.Secret)) | ||||
| 	} else { | ||||
| 		secret := make([]byte, opts.SecretSize) | ||||
| 		_, err := rand.Read(secret) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 		v.Set("secret", b32NoPadding.EncodeToString(secret)) | ||||
| 	} | ||||
|  | ||||
| 	v.Set("secret", base32.StdEncoding.EncodeToString(secret)) | ||||
| 	v.Set("issuer", opts.Issuer) | ||||
| 	v.Set("period", strconv.FormatUint(uint64(opts.Period), 10)) | ||||
| 	v.Set("algorithm", opts.Algorithm.String()) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user