patrickfav/bcrypt

View on GitHub

Showing 20 of 32 total issues

File BCryptOpenBSDProtocol.java has 377 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// Copyright (c) 2006 Damien Miller <djm@mindrot.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.

    File BCrypt.java has 360 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    package at.favre.lib.crypto.bcrypt;
    
    import at.favre.lib.bytes.Bytes;
    import at.favre.lib.bytes.BytesTransformer;
    import at.favre.lib.bytes.BytesValidators;
    Severity: Minor
    Found in modules/bcrypt/src/main/java/at/favre/lib/crypto/bcrypt/BCrypt.java - About 4 hrs to fix

      Method parse has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

              @Override
              public BCrypt.HashData parse(byte[] bcryptHash) throws IllegalBCryptFormatException {
      
                  if (bcryptHash == null || bcryptHash.length == 0) {
                      throw new IllegalArgumentException("must provide non-null, non-empty hash");

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method decode has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

              @Override
              public byte[] decode(byte[] in) {
                  // Ignore trailing '=' padding and whitespace from the input.
                  int limit = in.length;
                  for (; limit > 0; limit--) {

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method parse has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              @Override
              public BCrypt.HashData parse(byte[] bcryptHash) throws IllegalBCryptFormatException {
      
                  if (bcryptHash == null || bcryptHash.length == 0) {
                      throw new IllegalArgumentException("must provide non-null, non-empty hash");

        Method decode has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                @Override
                public byte[] decode(byte[] in) {
                    // Ignore trailing '=' padding and whitespace from the input.
                    int limit = in.length;
                    for (; limit > 0; limit--) {

          Method parse has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static Arg parse(String[] inputArgs) {
                  Options options = setupOptions();
                  CommandLineParser parser = new DefaultParser();
                  Arg argument = new Arg();
          
          

            Method hashRaw has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    public HashData hashRaw(int cost, byte[] salt, byte[] password) {
                        if (cost > MAX_COST || cost < MIN_COST) {
                            throw new IllegalArgumentException("cost factor must be between " + MIN_COST + " and " + MAX_COST + ", was " + cost);
                        }
                        if (salt == null) {
            Severity: Minor
            Found in modules/bcrypt/src/main/java/at/favre/lib/crypto/bcrypt/BCrypt.java - About 1 hr to fix

              Method hashRaw has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                      public HashData hashRaw(int cost, byte[] salt, byte[] password) {
                          if (cost > MAX_COST || cost < MIN_COST) {
                              throw new IllegalArgumentException("cost factor must be between " + MIN_COST + " and " + MAX_COST + ", was " + cost);
                          }
                          if (salt == null) {
              Severity: Minor
              Found in modules/bcrypt/src/main/java/at/favre/lib/crypto/bcrypt/BCrypt.java - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method execute has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  static int execute(Arg arguments, PrintStream stream, PrintStream errorStream) {
                      if (arguments == null) {
                          return 2;
                      }
              
              

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method cryptRaw has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  byte[] cryptRaw(long rounds, byte[] salt, byte[] password, int[] cdata) {
                      if (rounds < 0) {
                          throw new IllegalArgumentException("rounds must not be negative");
                      }
              
              

                Method parse has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    public static Arg parse(String[] inputArgs) {
                        Options options = setupOptions();
                        CommandLineParser parser = new DefaultParser();
                        Arg argument = new Arg();
                
                

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method verifyBCrypt has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                        private static Result verifyBCrypt(Version version, LongPasswordStrategy longPasswordStrategy,
                                                           byte[] password, int cost, byte[] salt, byte[] rawBcryptHash23Bytes) {
                Severity: Minor
                Found in modules/bcrypt/src/main/java/at/favre/lib/crypto/bcrypt/BCrypt.java - About 45 mins to fix

                  Method handleHash has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private static Arg handleHash(CommandLine commandLine, char[] password) {
                          String[] hashParams = commandLine.getOptionValues(ARG_HASH);
                  
                          if (hashParams == null || hashParams.length == 0) {
                              throw new IllegalArgumentException("Hash mode expects at least the cost parameter. (e.g.  '-" + ARG_HASH + " 12')");

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method innerVerifyBytes has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                          private Result innerVerifyBytes(byte[] password, byte[] bcryptHash, boolean strict) {
                              Objects.requireNonNull(bcryptHash);
                  
                              try {
                                  final Version usedVersion;
                  Severity: Minor
                  Found in modules/bcrypt/src/main/java/at/favre/lib/crypto/bcrypt/BCrypt.java - About 45 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Consider simplifying this complex logical expression.
                  Open

                                  if (c == '.' || c == '/' || (c >= 'A' && c <= 'z') || (c >= '0' && c <= '9')) {
                                      bits = DECODE_TABLE[c];
                                  } else if (c == '\n' || c == '\r' || c == ' ' || c == '\t') {
                                      continue;
                                  } else {

                    Method equals has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        @Override
                        public boolean equals(Object o) {
                            if (this == o) return true;
                            if (o == null || getClass() != o.getClass()) return false;
                            Arg arg = (Arg) o;
                    Severity: Minor
                    Found in modules/bcrypt-cli/src/main/java/at/favre/lib/crypto/bcrypt/cli/Arg.java - About 35 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Method cryptRaw has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        byte[] cryptRaw(long rounds, byte[] salt, byte[] password, int[] cdata) {
                            if (rounds < 0) {
                                throw new IllegalArgumentException("rounds must not be negative");
                            }
                    
                    

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Avoid too many return statements within this method.
                    Open

                            return argument;

                      Method equals has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                              @Override
                              public boolean equals(Object o) {
                                  if (this == o) return true;
                                  if (o == null || getClass() != o.getClass()) return false;
                                  Result result = (Result) o;
                      Severity: Minor
                      Found in modules/bcrypt/src/main/java/at/favre/lib/crypto/bcrypt/BCrypt.java - About 25 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Severity
                      Category
                      Status
                      Source
                      Language